briansgl Posted March 3, 2014 Share Posted March 3, 2014 I am currently working on file uploads. I already know how to upload a file to a folder E.G. creating the temp folder and then the final destination folder. The scenario is: I have a user table and when a user is logged in I need him to upload a file. Does the user upload it to a folder on the site and if so how do I join the file to the user which it relates or does the user need to upload it to a table in the database and again if so how to I attach it to the user the file relates to? There are basically 2 files that I need the user to upload. one is an image and the other is a PDF file. Thanks for any help with this. Link to comment Share on other sites More sharing options...
Larry Posted March 3, 2014 Share Posted March 3, 2014 If you're going to have a lot of users and files, I would recommend create a folder for each user and then store each uploaded file within there. Rename each file, too, using the ID from the database. So you have a 'users' table and a "files" table. The files table would reflect the user ID along with the other data. Then a file might be stored as x/y, where "x" is the user ID and "y" is the file ID. There are limits to how many things can be in a directory on some operating systems, so if you imagine having a ton of users, you'd need to create parent folders for the user folders, e.g., users_to_1000, users_to_2000, etc. Link to comment Share on other sites More sharing options...
willbun Posted April 21, 2015 Share Posted April 21, 2015 Hello, I'm reading Chapter 10 of your book (php 6 and MYSQL 5) and tried to run the file upload_image .php and i get these errors: Warning: move_uploaded_file(../uploads/William.jpg): failed to open stream: No such file or directory in /home1/willbun/public_html/ecommerce/upload_image.php on line 28 Warning: move_uploaded_file(): Unable to move '/tmp/phpVkBh7I' to '../uploads/William.jpg' in /home1/willbun/public_html/ecommerce/upload_image.php on line 28 Could you please help. Link to comment Share on other sites More sharing options...
Larry Posted April 22, 2015 Share Posted April 22, 2015 Have you created a writable "uploads" directory in /home1/willbun/public_html? Link to comment Share on other sites More sharing options...
willbun Posted April 22, 2015 Share Posted April 22, 2015 Ok! It's working now. But i can't see the picture on the page. Link to comment Share on other sites More sharing options...
Larry Posted April 25, 2015 Share Posted April 25, 2015 You can't see the picture on what page? What is the URL you're running? What is the result? Link to comment Share on other sites More sharing options...
willbun Posted April 26, 2015 Share Posted April 26, 2015 The URL is:http://www.webdesign213.com/upload_image.php when i upload an image, i get this "The file has been uploaded!" And when i check the folder: uploads in directory in /home1/willbun/public_html I see the image. But is not showing on the above URL. Link to comment Share on other sites More sharing options...
Larry Posted April 27, 2015 Share Posted April 27, 2015 The upload_image.php script only uploads the image. It doesn't show it. That's what images.php and show_image.php is for. Link to comment Share on other sites More sharing options...
willbun Posted April 27, 2015 Share Posted April 27, 2015 Alright! Thanks a lot for the info... Link to comment Share on other sites More sharing options...
Recommended Posts