Advanced Image Upload Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Advanced Image Upload Question

Post by Mr. Tech »

Yo!

I know how to upload a file with php ok.

My only problem is this how do I get the script to check if the file already exists, and then ask if you want to overwrite the file. If you click yes it will overwrite, if you click no it will not upload.

How do I do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]file_exists[/php_man] for checking existance. Then write a specialized form to handle the overwrite dialog. The upload would have to have already happened by this point. Instead of moving the file, it'd just [php_man]unlink[/php_man] to delete the temporary file..
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Code: Select all

<?php
$paste_name = $file_name;
while (file_exists($paste_name))
{
    $paste_name = rand(0, 9).$paste_name;
}
?>
Post Reply