File Upload Using Php

liunx

Guest
Hi,<br /><br />I've been having a lot of trouble uploading files from an HTML form to a directory on my server. I have set all of the appropriate permissions to 777 and I have used code from other topics on this forum to try to make this work.<br /><br />Here is the code that I am using for my HTML form.<br /><br /><form enctype="multipart/form-data" method="post" action="upload.php"><br /><br />Send this file: <input name="userfile" type="file"><br><br /><input type="submit" value="Send File"><br /><br /><br /></form><br /><br /><br />Here is the code that I am using for upload.php. I have taken out my user name where all of the *'s are.<br /><br /><?php<br /><br />$uploadDir = '/home/********/public_html/images/';<br />$uploadFile = $uploadDir . basename($_FILES['userfile']['name']);<br /><br />if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))<br />{<br />echo "File {$_FILES['userfile']['name']} was uploaded successfully.\n";<br />}<br />else {<br />echo "Upload Failed!\n";<br />}<br />?><br /><br /><br />Here are the error messages that I am receiveing:<br /><br />Warning: move_uploaded_file(/home/********/public_html/images/aap_dyk_issue9_img1.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/*******/public_html/upload.php on line 6<br /><br />Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFbCAfc' to '/home/********/public_html/images/aap_dyk_issue9_img1.gif' in /home/********/public_html/upload.php on line 6<br />Upload Failed!<br /><br />I have been all over this forum and other tutorials for the past week and I still cannot get this to work. The error that I have been receiving from most of my attempts using a lot of different code seem to be around using "move_uploaded_file()". Any help on this would be appreciated. Thanks.<!--content-->
When you get it to work, be sure to disallow search engine robots from accessing the directory where the uploaded files are, or you'll be inundated with spammy pages quickly!<br /><br />There is a script made for file uploads that you could use. Just search for it.<br /><br />Also, the more scripts you have, the more holes you put in your site, and the more risk there is of a hacker gaining control over your site.<!--content-->
Welcome to the forums kylebuch8 <br /><br />As annie states there are upload scripts already written and available. Check out hotscripts.com<!--content-->
I tried your script and it worked fine for me, I would verify your permissions.<!--content-->
Thanks everyone. The script worked as it should have. It turned out it was a problem with permissions. I felt like an idiot when I found that out. I've got everything worked out now. Thanks for all your help.<!--content-->
 
Back
Top