Jump to content


Photo

How to not overwrite an uploaded file name ?


  • Please log in to reply
3 replies to this topic

#1 Chrisj

Chrisj
  • Members
  • PipPipPip
  • Advanced Member
  • 325 posts

Posted 18 December 2017 - 05:33 PM

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.

 



#2 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,873 posts
  • LocationWA

Posted 19 December 2017 - 12:02 AM

The Javascript shouldn't be the one that sets the filename. Do it in uploadDrop.php. Whose code you did not post.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer

#3 Chrisj

Chrisj
  • Members
  • PipPipPip
  • Advanced Member
  • 325 posts

Posted 19 December 2017 - 06:10 PM

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.



#4 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,873 posts
  • LocationWA

Posted 20 December 2017 - 02:50 AM

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.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users