TCH-RobertM Posted December 6, 2004 Posted December 6, 2004 Is it allowed to have a user upload files to a website here ? I am still somewhat new to all this PHP stuff and am trying many things while learning. What I am attempting to do is allow my users (mostly family) a way to upload Photos to my site where I can then have a script call the files to display them. I am trying to get the upload process to work and I am running into some issues. I will post the code and then show error message One thing to note is that I changed the permissions to the upload directory so all users could write to the directory so I dont think that is the issue there are 2 files that make this process work the first file is > <h2>File Upload Form</h2> <form enctype="multipart/form-data" method="post" action="upload2.php"> Send this file: <input name="userfile" type="file" /><br /> <input type="submit" value="Send File" /> </form> The second file is called upload2.php ><?php if (move_uploaded_file($_FILES['userfile']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."/UPLoaded_FILES/")) { print "Received {$_FILES['userfile']['name']} - its size is {$_FILES['userfile']['size']}"; } else { print "Upload failed!"; } ?> The error message I am getting is Warning: move_uploaded_file(/home/rmulher/public_html/UPLoaded_FILES/): failed to open stream: Is a directory in /home/rmulher/public_html/php/upload2.php on line 2 Warning: move_uploaded_file(): Unable to move '/tmp/phpILFGeK' to '/home/rmulher/public_html/UPLoaded_FILES/' in /home/rmulher/public_html/php/upload2.php on line 2 Upload failed! any insight as to why this is occuring would be appreciated. Thank you Robert Quote
TCH-Thomas Posted December 6, 2004 Posted December 6, 2004 Yes, it would be ok as long you guys dont violate any copyrights etc. As for the script... You say its photos, have you considered installing one of the popular galleris too make the upload and viewing real simple? Im no code guy so maybe that code will make it even more simple, if so please disregard this. Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 Hi Thomas, Yes I have I am not sure I want that kind of overhead though yet.... I also would not atomate the process until I viewed the actual pictures.... the generate code script would be run periodically by me after I approved pictures I just cant seem to get past the permissions problem I think I ahve checked everything on my side and only thing I Can come up with is maybe I need to create a .htaccess and make settings in there ..... I am not sure though Quote
jandafields Posted December 6, 2004 Posted December 6, 2004 Make sure that the directory /home/rmulher/public_html/UPLoaded_FILES/ actually exists. Also, make sure to chmod that directory to either 777 or 666. That is very important. Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 I have created the Directory /home/rmulher/public_html/UPLoaded_FILES/ and it is chmod 777 I Do not see any other reasons why this is not working other than I will have to look into the .htaccess file and see fi that helps. I have not had any time last night to look at that hopefully that will shed some light... if there are any other reasons that a problem could exist please let me know Thank you again everyone for looking and helping me with this Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 Ok just so all of you know what I am finding out, I have narrowed it down to when uploading the file you must specify a file name in the Directory your trying to move it to. I am working on that and will publish my code once I have it working. Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 ok here is what I did to get everything to work correctly Step 1 was I created an Upload directory where I wanted files to be placed. Chmod that directory to 777 or 666 depending on your preference. I chose 777 for now Step 2 was I put the following code on the page where I wanted the user to upload files from ><h2>File Upload Form</h2> <form enctype="multipart/form-data" method="post" action="upload2.php"> Send this file: <input name="userfile" type="file" /><br /> <input type="submit" value="Send File" /> </form> Then I created the upload2.php file with the following code Note you will have to change the {userid} or the entire uploaddir to whatever you need. ><?php $uploaddir = '/home/{userid}/public_html/UPLoaded_FILES/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File {$_FILES['userfile']['name']} was successfully uploaded.\n"; } else { echo "Upload Failed!\n"; } ?> Everything works smooth now Thank you all. Quote
TCH-Thomas Posted December 6, 2004 Posted December 6, 2004 Great to hear its working. I might try this myself one day if you dont mind. Quote
TCH-Don Posted December 6, 2004 Posted December 6, 2004 The folder needs to be 777 Thanks for the update, its alway nice to get a script working good job Thumbs Up Quote
jandafields Posted December 6, 2004 Posted December 6, 2004 The folder needs to be 777 Thanks for the update, its alway nice to get a script working good job Thumbs Up As opposed to 666? Or are you just making sure we remember to chmod? Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 My understanding of Permissions is that if a File is 777 which stand for read write and execute for everyone if the file was 666 than the file permisions would be Read and Write for everyone no need to have execute permisions on a directory that has only pictures. I am not sure if the execute bit needs to be set but I would think it does not will play with it later and see Quote
jandafields Posted December 6, 2004 Posted December 6, 2004 No, it needs to be 777 666 gives write permissions to everybody. Why does it need to have execute permissions as well??? Edit: rmulhern, you beat my post by 1 second Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 ok after a quick test I have found that 777 was the only way I could get this to work I tried 666 I tried 766 and I tried 776 These combinations did not work. I am not sure why the execute bit needs to be set for writing to a directory, but for the purpose of uploading the file without problems 777 was the only solution that worked for me psst jandafields thats only because I am a newcomer that I beat you LOL Quote
TCH-Don Posted December 6, 2004 Posted December 6, 2004 I tried 666, 766 and 776 and I received errors with 777 it works. Keeping that in mind this script does not check to what type of files are uploaded. Someone could upload a script and run it. if you want security hotscripts will have file uploader that will check the file type. Quote
TCH-RobertM Posted December 6, 2004 Author Posted December 6, 2004 Don that was one of the things I am going to put into place next, as well as password protect the directory so that only family members and people I authorize will be capable of uploading them.. One of the major concerns I have is that if a person uploads a file that may contain a virus...... this is somthing I need to research as well any thoughts ? Quote
TCH-Don Posted December 6, 2004 Posted December 6, 2004 (edited) A link to celerondude upload script (under php) was posted here not long ago. I just downloaded it and set up a folder for photos, chmod to 777 installed the script, chomd the files in the instruction.txt logged and modified the setting to point to the folder and added a user and it works very well you can set the file type. You may want to study this to see how its done. Edited December 6, 2004 by TCH-Don Quote
TCH-Bruce Posted December 7, 2004 Posted December 7, 2004 (edited) No, it needs to be 777 666 gives write permissions to everybody. Why does it need to have execute permissions as well??? Because it's a folder and not a file is the reason for 777. For anyone to be able to write to a folder it has to be 777. Edited December 7, 2004 by TCH-Bruce Quote
jandafields Posted December 7, 2004 Posted December 7, 2004 Thanks for the clarification, Bruce. Quote
TCH-RobertM Posted December 7, 2004 Author Posted December 7, 2004 Yes Thank you Bruce, I knew there had to be an explanation, Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.