0

I am trying to setup a filefield using imce to allow the user to upload files however I am having problems setting it up trying to get a unique folder for each node.

So for example I have set the imce directory path to

php: return $user->name.'/'.date('Y-m-d-H-i');

Which will upload files to user/2015-06-12-13-15.

However when the I click use the file browser if I don't upload the file within the same minute as when I clicked use the file browser, IMCE throws an error saying the directory doesn't exist as I imagine the date change throws off the upload.

I don't want to restrict users creating one node an hour so does anyone know of another way of generating random file paths for each node?

0

This probably isn't the best solution, however it is working for me at the moment.

Using the following php in the IMCE directory path it generates the same random number for 5 minutes. So I can have the directory structure user/Y-m-d-H-[random number]

php: function random() {  $seed = floor(time()/(60*5)); srand($seed); $item = rand(0,100); return $item; }  return $user->name.'/'.date("Y-m-d-H").'-'.random();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.