Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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!
    Last edited by BroChris; 07-02-2004 at 12:10 AM.

  • #2
    New Coder
    Join Date
    Jul 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure you have permission [The file is CHMOD'd 777]?

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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)

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Works great, THANK YOU!!!

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •