Jump to content
Larry Ullman's Book Forums

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×