Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2004, 11:06 PM   PM User | #1
BroChris
Regular Coder

 
Join Date: Jun 2002
Location: Louisville, KY
Posts: 279
Thanks: 0
Thanked 0 Times in 0 Posts
BroChris is an unknown quantity at this point
can't delete created file(s)

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:

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!
__________________
designsbychris.com

Last edited by BroChris; 07-01-2004 at 11:10 PM..
BroChris is offline   Reply With Quote
Old 07-02-2004, 12:03 AM   PM User | #2
Lamper
New Coder

 
Join Date: Jul 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Lamper is an unknown quantity at this point
Sure you have permission [The file is CHMOD'd 777]?
Lamper is offline   Reply With Quote
Old 07-02-2004, 02:24 AM   PM User | #3
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 07-02-2004, 01:55 PM   PM User | #4
BroChris
Regular Coder

 
Join Date: Jun 2002
Location: Louisville, KY
Posts: 279
Thanks: 0
Thanked 0 Times in 0 Posts
BroChris is an unknown quantity at this point
Works great, THANK YOU!!!
__________________
designsbychris.com
BroChris is offline   Reply With Quote
Old 07-08-2004, 03:12 PM   PM User | #5
BroChris
Regular Coder

 
Join Date: Jun 2002
Location: Louisville, KY
Posts: 279
Thanks: 0
Thanked 0 Times in 0 Posts
BroChris is an unknown quantity at this point
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?
__________________
designsbychris.com
BroChris is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 AM.


Advertisement
Log in to turn off these ads.