Page 1 of 1

Save file to user directory and link/href saved to mysql

Posted: Wed Jul 09, 2008 9:42 am
by cjmartinez2285
Hi All,

I have been trying to work on a project for a bit here and am having a little bit of trouble. What I am trying to do is have a registered user be able to upload multiple files to their own user directory through the front-end (logged in) of my site, and then be able to save the location of the file (href) to the Mysql db so that I can output it as a list to the user so that they can see their uploaded files and click to view them.

Any help would be greatly appreciated. I can also provide more information on my goals if I didn't explain too well.

Im actually trying to incorporate this into the modx cms.

Re: Save file to user directory and link/href saved to mysql

Posted: Wed Jul 09, 2008 3:56 pm
by Benjamin
What you want to accomplish is fairly simple.

Upload Process
1. Bob uploads a file.
1a. Validate the file.
2. Check if a folder exist in the uploads folder with Bob's user id
2a. If not, create it.
3. Save the file in Bob's folder
3a. CHMOD the file
4. Save the file name into a database table that contains user_id and file_name fields.

List Process
1. Query the uploads table for all files uploaded by a particular user_id
2. Output each item as "http://yoursite.com/" . "{$user_id}/{$file_name}"

Re: Save file to user directory and link/href saved to mysql

Posted: Thu Jul 10, 2008 3:01 pm
by cjmartinez2285
Hi astions,

I understand the process it needs to go through but my code is not working, I have it pulling the array, no problem. The hard part is to somehow have it upload the file itself to the users created directory, and also, have it store the url (file location) into a database table which I will print to the viewer.

Any thoughts (specific), if you would like and allow me to, I can send you the source that I have so far.

Re: Save file to user directory and link/href saved to mysql

Posted: Thu Jul 10, 2008 3:08 pm
by Benjamin
There are good examples here: http://us2.php.net/manual/en/features.file-upload.php

Be sure to set the form enctype="multipart/form-data"

If you get stuck feel free to post your code here and either I or someone else will help you.