Chrisj Posted December 18, 2017 Share Posted December 18, 2017 I'm using dropzone js successfully to upload files from a web page.However, if a file gets uploaded that has the same name as a file already in the destination folder, it will overwrite the existing folder file. I tried to remedy this by adding the js script function as shown below, but it didn't work: <div id="dropzone"> <form action="/uploadDrop.php" class="dropzone"></form> </div> <script type="text/javascript"> Dropzone.autoDiscover = false; $(document).ready(function () { $(".dropzone").dropzone({ renameFilename: function (filename) { return new Date().getTime() + '_' + filename; } }); }); </script> Any help with this will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/305938-how-to-not-overwrite-an-uploaded-file-name/ Share on other sites More sharing options...
requinix Posted December 19, 2017 Share Posted December 19, 2017 The Javascript shouldn't be the one that sets the filename. Do it in uploadDrop.php. Whose code you did not post. Quote Link to comment https://forums.phpfreaks.com/topic/305938-how-to-not-overwrite-an-uploaded-file-name/#findComment-1554758 Share on other sites More sharing options...
Chrisj Posted December 19, 2017 Author Share Posted December 19, 2017 Thanks for your message. Here is the uploadDrop.php code: <?php $ds = DIRECTORY_SEPARATOR; $storeFolder = 'uploadDrop'; if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; $targetFile = $targetPath. $_FILES['file']['name']; move_uploaded_file($tempFile,$targetFile); } ?> Any additional help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/305938-how-to-not-overwrite-an-uploaded-file-name/#findComment-1554786 Share on other sites More sharing options...
requinix Posted December 20, 2017 Share Posted December 20, 2017 That is not good. Anyone can upload any file to any directory on your server. Here is a link that looks good to me. Ignore the Cloudinary stuff. Read and understand what it does, then adjust it to work with your site. Quote Link to comment https://forums.phpfreaks.com/topic/305938-how-to-not-overwrite-an-uploaded-file-name/#findComment-1554789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.