Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Image Replacement

Posted on 2003-12-05
3
Medium Priority
?
228 Views
Last Modified: 2009-07-29
Thanks for taking the time to read this ..

I have an image upload script that works perfectly .. now i want , that if an image is uploaded with the same name as an image that already exists it replaces the image with the new one..

i tried removing the section below but that just produced new errors

All help welcome even if it is another script that does what i want or a link to one.


*************************************************
Section i tried removing
 
if(file_exists("$ADMIN[directory]/$picture1") OR $ok == 2) {
$error .="File name already exists for file $num<BR>";
} else {
copy ($picture3, "$ADMIN[directory]/$picture1");
$error .="File $num has been uploaded<BR>";
}
}
}
*************************************************



FULL SCRIPT


<?php
exit();
}
}

$num = 0;
while($num < $ADMIN[UploadNum]) {
$num++;


$picture = "fileup$num"."_name";
$picture1 = $$picture;
$picture2 = "fileup$num";
$picture3 = $$picture2;

if($picture3 != "none") {
$filesizebtyes = filesize($picture3);

$ok = 1;
if($filesizebtyes < 10) {
$error .= "Error uploading (file size lower than 10 bytes) for file $num<BR>";
$ok = 2;
}



if(file_exists("$ADMIN[directory]/$picture1") OR $ok == 2) {
$error .="File name already exists for file $num<BR>";
} else {
copy ($picture3, "$ADMIN[directory]/$picture1");
$error .="File $num has been uploaded<BR>";
}
}
}

if(!$error) {
$error .= "No files have been selected for upload";
}


?>

Cheers

Steve
0
Comment
Question by:stelogic
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 1000 total points
ID: 9881975
According to the help, the copy() function will always overwrite existing images.

"If the destination file already exists, it will be overwritten. "

So.

Are you sure that the image is NOT being overwritten?

With your script if the image exists, it will NEVER be overwritten.

I assume that $ok means that the overwrite is allowed?

If so, then (and assuming $ok is a boolean), try ...

if(file_exists("$ADMIN[directory]/$picture1") AND $ok === False)

This says, if the image exists AND they have NOT said it is OK, then don't copy.

If the image does NOT exist OR they have said it IS ok to copy, then the copy function will work.

Richard.
0
 

Author Comment

by:stelogic
ID: 9882066
Genius Mate..Pure Genius

Thanks

Steve


0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 9895936
Anything else needed on this question?

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question