RE: Multiple file Delete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm not understanding the logic in all the loops and such here. And why comparing the first 5 characters?  That seems kind of dangerous.

Why don't you pass the name of the main file ($file = "image1.jpg" for example) then:

1. unlink $file in images
2. unlink $file in big
3. unlink $file . ".txt" in big

I don't follow the logic of looping through the files in a folder unless you might have other files associated with the image+thumbnail+descriptionfile that you can't anticipate.  In which case, I wouldn't check the first 5 characters, I'd check:

If (Mid($FileInDir,0,strlen($FileToDelete)) = $FileToDelete) unlink($FileInDir);


Then you're checking the full "image1.jpg" and not "image" (first 5 characters... What happens if you have an "image2.jpg", does it and it's associated thumbnail and description files get deleted too?)


I only gave this script a cursory look-over, so forgive me if I missed something, but by the comments and the quick glance of the code, I'm assuming that I understand what's going on.

-TG


> -----Original Message-----
> From: Lenny Davila [mailto:Lenny@xxxxxxxxxxxxxxxxxx] 
> Sent: Wednesday, June 16, 2004 4:08 PM
> To: php-windows@xxxxxxxxxxxxx
> Subject:  Multiple file Delete
> 
> 
> I need to be able to delete multiple files from my web server 
> by choosing one file.  I have a directory of thumbs named
> "images" and a directory called "big" with text files and
> Full images.  If I was to delete the file "image1.jpg" I
> want it to delete "image1.jpg" in the images, the big folder
> and "image1.jpg.txt" in the big folder.  I have now in my code.
> ($file = file to be deleted)
> 
>    if($action=="dele" && $confirm==1) {
>    $match=array(); 
> // Create an array of files
>   $match[]=$file; 
> // Put filename in the array
>    
>   $dirHandle = dir('../'); 
> // get recursive directory listing from the directory above
>   while($fileHandle = $dirHandle->read()) { 
> // while reading the directory
>     $delFile = strrchr($fileHandle, "/"); 
> // get the filename after the last "/"
>     if (in_array(substr($delFile,0,5), $match)) { 
> // this line compares the 5 first chars in the filename 
> // with the names in the $match array 
> // Next line is line 36
>     unlink($delFile); $action="";} 
> // delete all files that match the filename
>       if (unlink($delFile)) { 
>           echo "Removed the file $fileHandle<br> \n"; 
>       } 
>     } 
>   }
> 
> The first error I get:
> Warning: unlink(): No such file or directory in
> /home/www/mathiu1i/php/gallerie/edit2.php on line 36
> 
> 
> TIA
> ------------------------------------
> Eleno Davila
> lenny@xxxxxxxxxxxxxxxxxx
> (877)933-6750 Ext 163 (direct line)
> http://plasticsurgery.com ;

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux