Solved

Image Replacement

Posted on 2003-12-05
3
211 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 250 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

831 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