Welcome Guest ( Log In | Register )



2 Pages V  < 1 2  
Reply to this topicStart new topic
> PHP Script To Upload A File, with password-protection.
nightfox
post Mar 19 2006, 05:52 AM
Post #11


NiGHTFoX - Hiding in the dark
Group Icon

Group: Members
Posts: 680
Joined: 3-April 05
Member No.: 3,584



QUOTE(Vyoma @ Mar 8 2006, 08:46 PM) *

vujsa, I am sorry, I forgot to mention that I had tried the FTP option earlier. The network administrator here is a real security-paranoid.

Heh... they all seem to be that way, lol.

Perhaps if you're interested, you can upload files directly through cpanel to your web space. Here's a HOWTO:

1) Login to cPanel (http://yourURL/cpanel) with your username and password.
2) Under "Site Management Tools" in the first row, last column, you should see an icon labled as "File Manager". Click it.
3) A new window will open. You should see your home directory (outside public_html folder). Click the folder icon (NOT the folder name!) next to "public_html"
4) Click on the link in the top "Upload files" and you can upload 12 files at once!
5) Click on the link in the top "New folder" to add a new folder.
6) Click on a folder or file NAME (not the icon) to change its properties (CHMOD, re-name, etc), delete, edit, etc.

Good Luck! This will be much easier and is built into cpanel. You won't need to worry about getting a PHP script in and then keeping that script secure. wink.gif

Best of luck with building your site the hard way (uploading through cpanel) but I suppose with security freaks on the other end of the proxy, you'll have to do it this way.

[N]F
Go to the top of the page
 
+Quote Post
Vyoma
post Mar 21 2006, 01:12 PM
Post #12


Cosmic Overlord
Group Icon

Group: Members
Posts: 571
Joined: 26-November 05
From: Denver, Colorado, US
Member No.: 9,811
myCENTs:45.66



nightfox, I cannot use the FTP option and the cpanel (that port is blocked). I have to go out to a net cafe to do it. Hence, I came up with this option that may work out.
Go to the top of the page
 
+Quote Post
KazDoran
post Mar 31 2006, 09:48 AM
Post #13


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 49
Joined: 7-March 06
Member No.: 11,803



Hi!

I was actually working on a PHP script to do just that. And unfortunately, it seems it won't work, for some reason. I've been asking around to find out what's wrong (I see the file isn't even uploaded as temporary file) and it may be that the PHP server in Astahost is running as root, and as such we needed root access to do the file upload... Not entirely sure though.

EDIT: Actually, it looks like the PHP upload_tmp_dir variable is empty, and that's why I can't put the files there as well...

This post has been edited by KazDoran: Mar 31 2006, 09:55 AM
Go to the top of the page
 
+Quote Post
KazDoran
post Mar 31 2006, 12:02 PM
Post #14


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 49
Joined: 7-March 06
Member No.: 11,803



Yay I got it to work!

Here's how it goes, a very simple script, without password verification:

1) CHMOD your /tmp directory to 775 (very important!)

2) Create a form like this:

CODE
<form enctype="multipart/form-data" action="process.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
File: <input type="file" name="uploadedfile"><br>
<input type="submit" value="Submit">
</form>


You MUST have enctype="multipart/form-data" or the file upload won't work!
MAX_FILE_SIZE limits the maximum file size, in bytes (in this case, around 50 KB).

3) Now the script inside process.php:
CODE

<?
$upload_dir="upload/"

$upload_path = $upload_dir . basename($_FILES['uploadedfile']['name']);

if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_path)){
    echo "Upload failed.";
    }
?>


Set the $upload_dir variable to whatever directory you wish to upload the file to.
The $upload_path variable will be the relative path to the file when it's in place.
If by any chance the file fails to upload, you'll be notified.

Hope this will help. To create a password protection just create a new form where you type the password and do a basic check to see if it matches. wink.gif
Go to the top of the page
 
+Quote Post

2 Pages V  < 1 2
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Trainable Anti-spam Filter Script(3)
  2. Php Script To Download File From Another Site(9)
  3. Counter With Img In Flat File(2)
  4. Need Help With A PHP - MySQL Registration Script(13)
  5. [PHP + MySQL] Encrypting Data(11)
  6. What Would Make A Good Registration Script?(4)
  7. Authentication Script(1)
  8. Login Script(5)
  9. Please Help (php Join Script)(5)
  10. Automatic/remote Php Script Execution(9)
  11. Php File Upload(3)
  12. Something Wrong With This Script?(9)
  13. Extplorer(7)
  14. Automated Product Suggestion Script(2)
  15. Run A Script When Expires A Session(6)
  1. Php Script Help(1)
  2. SQL Doesn't Connect In PHP Script(19)
  3. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  4. Password Recovery Script(6)
  5. Login Script(8)
  6. Free Forum Hosting Type Script Help!(2)
  7. Script Request(2)
  8. Writing And Testing My Own Login Script [solved](20)
  9. Make A Script Run Even If No User Is Online(6)
  10. Php Login Script(0)
  11. Myspacetv Download Php Script Help(6)
  12. How To Include A File Using Absolute Paths Under A Secure Php Installation(6)
  13. Php Script Organizer(3)


 



- Lo-Fi Version Time is now: 5th December 2008 - 04:54 PM