Register for your free account! | Forgot your password?

You last visited: Today at 22:14

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



PHP HELP

Discussion on PHP HELP within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Aug 2012
Posts: 1
Received Thanks: 0
PHP HELP

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)) {

}
?>
bluedemon001 is offline  
Old 08/05/2012, 22:03   #2


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,913
Received Thanks: 25,413
Arrow General Coding -> Web Development

#moved
MrSm!th is offline  
Old 08/06/2012, 04:03   #3
 
Mikesch01's Avatar
 
elite*gold: 203
Join Date: Sep 2007
Posts: 732
Received Thanks: 190
Use the function from php in an if block to check this.
Mikesch01 is online now  
Old 08/08/2012, 14:55   #4
 
'Ownii's Avatar
 
elite*gold: 0
Join Date: Mar 2011
Posts: 270
Received Thanks: 769
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
'Ownii is offline  
Old 08/08/2012, 15:40   #5
 
kissein's Avatar
 
elite*gold: 0
Join Date: Sep 2005
Posts: 427
Received Thanks: 87
instead of
PHP Code:
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { 
use
PHP Code:
if ($_FILES['userfile']['error'] == 0) { 
kissein is offline  
Reply




All times are GMT +2. The time now is 22:14.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.