Solved

Image Replacement

Posted on 2003-12-05
3
210 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:
RQuadling 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:RQuadling
ID: 9895936
Anything else needed on this question?

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now