• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space

Check for existing file on server

wout000

Chevereto Member
In order for the chevereto script to check for existing files on a server (as to not overwrite them) some changes have to be made.

First off, the image uploaded needs to be placed in a tmp folder, so it can be checked against the other images on the server.

Here is an explanation and some examples of the code

http://us2.php.net/manual/en/function.file-exists.php

I would like to see the script checking for existing files, and automatically rename them if a file exists..

Explanation and some samples

http://ua.php.net/manual/en/function.rename.php

sample code:

Code:
<?php 
// Name of the uploaded file 
$name = $_FILES['uploadedFile']['name']; 
// Random 25 chars+nums . . . 
$your_25_digit_code = substr(md5(rand(0,9999)), 17, 25); 
// Get the file apart by ., so the 25 chars can be added before the extension 
$temp_arr = explode(".", $name); 
// Default it 
$original_name = ''; 
// Make sure the file isn't something like 
// image.something.whatever.hi.hello.what.s.up.png 
// Minus 2 because it would come out to 
// (file_name).(random_chars).(extension), 
// with this it comes out to (file_name)(random_chars).(extension) 
for ($x = 0; $x < count($temp_arr)-2; $x++) { 
   // Add to it 
   $original_name .= $temp_arr[$x] . '.'; 
} 
// The new file name 
$new_file = $original_name . $temp_arr[$x] . $your_25_digit_code . '.' . $temp_arr[$x+1]; 

$tempFile = $_FILES['uploadedFile']['tmp_name']; 
$destination = "C:\\ImageHosting\\" . $new_file; 
copy($tempFile, $destination); 

copy($_FILES['uploadedFile']['tmp_name'], 
   $_FILES['uploadedFile']['name']);
 
Correct way is md5 + db dude... Your code could overload any server.
 
Back
Top