2

im using dropzone.js in my project to upload articles image. for example all of article images will upload here:

www.site.com/images/uploads/.... .jpg

my dropzone usage

var myDropzone = new Dropzone("div#myId", { url: "/file/post"});
$("div#myId").dropzone({ url: "/file/post" });

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
</form>

i want automatically make a folder with (date) name every month in uploads folder and upload that mount images into this folder.

what can i do? tnx

K1-Aria
  • 1,093
  • 4
  • 21
  • 34

1 Answers1

2

To do this, You need to create a cron job in your server to create a new folder each month.

0 0 1 * * /usr/bin/mkdir /yourDir/$(date +%Y%m)

Or by running server code to create folder like this in PHP:

mkdir("/path/to/my/dir", 0755);

And then you can set your dropZone code to be like this:

 var today = new Date();
 var currentMonth = today.getFullYear() + '' + (today.getMonth()+1);
 var myDropzone = new Dropzone("div#myId", { url: "/file/post/" + currentMonth});

Note: make sure to set truth timezone for client and server. like get time at UTC....etc

Anees Hikmat Abu Hmiad
  • 3,460
  • 2
  • 19
  • 36
  • can we do this way? : check the (today) folder exist, when upload starts and if it exist, upload images into that folder and if dose not exist, create the folder – K1-Aria Oct 28 '18 at 14:35
  • 2
    Yes you can that..., by using server side language – Anees Hikmat Abu Hmiad Oct 28 '18 at 14:38
  • but i think your way is better. because when number of folders are very much, my way should check (today) folder exist of not. (between hundreds of folders) – K1-Aria Oct 28 '18 at 14:40