Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Image Replacement

Posted on 2003-12-05
3
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

688 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