...

View Full Version : can't delete created file(s)



BroChris
07-02-2004, 12:06 AM
Trying to get a simple image gallery working. The code does exactly what I want it to do, but I noticed that after it creates the thumbnails, the thumbnails cannot be deleted. Any idea why? Here's the code:


<?php

ini_set("max_execution_time", 5000000);

$width=100; // width of thumbnail size
$row = 4; // number of rows in the thumbnail table
$quality = 70;

$dir = ".";
$result = opendir($dir);

echo("<b>Admin</b><br><br>\n");
echo("<form method=post action=admin.php>\n");
echo("<select name=convert_dir>\n<option value=no>Select a directory\n");

while ($fn = readdir($result))
{
if ($fn != "." AND $fn != ".." AND is_dir($fn) AND !strstr($fn,'thumbnail_'))
{
if (!is_dir('thumbnail_'.$fn))
{
echo("<option value = \"$fn\">$fn\n");
}
}
}

closedir($result);

echo("</select><br><br>\n");
echo("<input type=submit value=\"Make Thumbnail\">\n</fonm><br>");

if (isset($_POST['convert_dir']) && $_POST['convert_dir'] != 'no')

{

$dir = $_POST['convert_dir'];
$opend = 'thumbnail_'.$dir;
@$opend_result = mkdir ($opend , 0777);

if ($opend_result)
{
$result = opendir($dir);
while ($fn = readdir($result))
{
if ($fn != "." AND $fn != ".." AND !is_dir($fn) AND stristr($fn,'jpg') )

{

// Resize Photo

//echo ($fn."<br>");
$size = getimagesize($dir."/".$fn);
//echo($size[0]." ".$size[1]."<br>");

if ($size[0] <= $width)
{

//copy
$copyfile = $opend."/".$fn;
$original_file =$dir."/".$fn;
copy($original_file , $copyfile);

}

else

{
$factor = $size[0] / $width;
$new_length = intval($size[1] / $factor);
$src_img = imagecreatefromjpeg($dir."/".$fn);
$dst_img = imagecreatetruecolor($width,$new_length);

$src_width=imagesx($src_img);
$src_height=imagesy($src_img);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $new_length, $src_width, $src_height);
imagejpeg($dst_img, $opend."/".$fn, $quality);
imagedestroy($src_img);
imagedestroy($dst_img);
}


}
}
closedir($result);

echo("<br><br><b>Done!</b><br>");
}

}

?>

I tried deleting the files both through ftp and cpanel. I'm really stumped on this one...help!

Lamper
07-02-2004, 01:03 AM
Sure you have permission [The file is CHMOD'd 777]?

firepages
07-02-2004, 03:24 AM
its all about ownage ;) when PHP creates the files it (or rather the webserver) owns them , you the user no longer own them and therefore can not do anything with them unless they have the right permissions set.

so 2 options ,
1) delete via script (as the script `owns` the file) , <?unlink('filename');?>
2) when you create the thumbnail, chmod it to something accessible at creation time <?chmod(0777,$dst_img);?> then you can still delete via FTP/SSH/Cpanel.

BroChris
07-02-2004, 02:55 PM
Works great, THANK YOU!!!

BroChris
07-08-2004, 04:12 PM
Still trying to customize this script for my needs, ran into another issue.

I'd like to put the scripts into a different sub-directory than the images. What's the right way to reference the other folders?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum