cformsII Support Forum
Current User: Guest *Frequently Asked Questions*
Search 
Search Forums:


 




Upload into new & unique directories?

Add a New Topic Reply to Post
Post

Dan is Sleepy and Co - Guest

3:30 pm - November 16, 2007

1
  • The URL: http://???
  • Browser (and version): ???
  • cforms version: 5.52
  • possibly other plugins that might interfere: 
    • ???
  • Do you get an error message (e.g. use Firebug):
    • ???

[desc]: I am hoping there is a simple solution to this, or even a complex one. It seems like there should be a way to do this...

When using the File Upload boxes, is there a way to get each submission to upload into a different and unique folder? Instead of putting all uploaded files into the same directory and tacking on a prefix to the filenames (1-photo.jpg, 2-photo.jpg...) could the plugin make new directories, where photo.jpg could be in folder 1 and folder 2 which are subdirectories of the main upload folder?

I am using a form right now that allows you to upload up to 10 photos and instead of those 10 new photos going into the default upload folder, I'd like the plugin to create a new subfolder under the default folder and put the images in there. It doesn't matter what the folder is called (001, 002...or created using the input of a field in the form like "Title of Photo Set").

Just to be clear, I have no problems uploading right now, it all works great. I'd just like to be able to get each submission automatically placed into dynamically created folders underneath the main upload folder.

Is this possible? It seems like you should just be able to stick a variable in the Upload Directory setting, but I haven't seen anything related to this anywhere in the forums or elsewhere.

Thanks so much if you can help in any way! 

Oliver - Admin

4:07 pm - November 16, 2007

posts 3909

2

What you could do is, change line 1346 in cforms.php (v552):

copy($tmpfile,get_option('cforms'.$no.'_upload_dir') .'/'.$subID.'-'.$file['name'][$filefield++]);

to

 copy($tmpfile,get_option('cforms'.$no.'_upload_dir') .'/'.$filefield. '/'.$subID.'-'.$file['name'][$filefield++]);

See if that works (create the directories first!). New dir structure should be:

(whatever configured)/1  [/2 ,  /3 etc.] 

Also, I'm not sure what happens when a user omits upload field #1 and starts with upload field #2, this file (from field #2) could end up in directory /1 !? Make sure to double check that. 

kingivor - Guest

10:29 am - April 9, 2008

3

I'm looking to do something like this too, but the code doesn't match up with the latest version of cformsII. Can something like this be worked out?


It looks like the code that was provided will create a new directory for each upload field, is that right? Could I get it so that all the files uploaded from the same form go into their own directory together?


Oliver - Admin

6:21 pm - April 9, 2008

posts 3909

4

The code has been moved. You'll find it in lib_nonajax.php (line 280).

What you're describing is the default.

  • per form you define the upload folder
  • uploaded files are numerated by tracked submission ID (you need to turn on cforms DB tracking!)

What the above code does, is to move each (his form has multiple upload fields in one form!) file into its own sub dir (/0/ for the first, /1/ for the second etc.).

Reply to Post


Reply to Topic: Upload into new & unique directories?
PLEASE READ THE FAQs FIRST! THANK YOU.

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Topic Reply:

Save New PostSmileysOptions

Guest URL (required)

Math Required!
What is the sum of:
10 + 5
   

 
Confused Cool Cry Embarassed Frown Kiss Laugh Smile Surprised Wink Yell

Search