PHP HELP

08/03/2012 16:50 bluedemon001#1
hello the following script i am using to upload pictures to my site can anyone help me make it check if the image exists and if it does tell the user that the picture is already there.

PHP Code:
<?php
$uploaddir 
'./';      //Uploading to same directory as PHP file

$file basename($_FILES['userfile']['name']);

$uploadFile $file;
$randomNumber rand(09999999999999);

$newName $uploadDir $randomNumber $uploadFile;

if (
is_uploaded_file($_FILES['userfile']['tmp_name'])) {
    echo 
"Temp file uploaded.";
} else {
    echo 
"Temp file not uploaded.";
}

if (
move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) {

}
?>
08/05/2012 22:03 MrSm!th#2
#moved
08/06/2012 04:03 Mikesch01#3
Use the function [Only registered and activated users can see links. Click Here To Register...] from php in an if block to check this.
08/08/2012 14:55 'Ownii#4
I don't understand your problem.. you use a randomnumber in your script, so it's not likely that this file exist but you can do it this way:

use a while function where you create a new file name as long as the file with the generated name exists
PHP Code:
<?php 
$uploaddir 
'./';      //Uploading to same directory as PHP file 

$file basename($_FILES['userfile']['name']); 

$uploadFile $file

while( 
file_exists($newName) ) {

    
$randomNumber rand(09999999999999); 

    
$newName $uploadDir $randomNumber $uploadFile

}



if (
is_uploaded_file($_FILES['userfile']['tmp_name'])) { 
    echo 
"Temp file uploaded."
} else { 
    echo 
"Temp file not uploaded."


if (
move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) { 


?>
sorry for my bad englisch but i hope i could help you ;)

sincerely Ownii
08/08/2012 15:40 kissein#5
instead of
PHP Code:
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { 
use
PHP Code:
if ($_FILES['userfile']['error'] == 0) { 
[Only registered and activated users can see links. Click Here To Register...]