Files from a Folder

See all posts Reply

Files from a Folder new!
by PlaynowGames, 16 years ago
I try get pics from a local folder, I get to do this, but the class don't crop and resize all pics in the folder.

does have in the class any limit for this?Reply
Re: Files from a Folder new!
by colin, 16 years ago
No, there aren't any limits, but the PHP time and memory limits.

What errors do you have?Reply
Re: Files from a Folder new!
by PlaynowGames, 16 years ago
I have no errors....

exemple:

I have 37 pic in the folder, but the class just resize and crop 27 or less

it's my code, take a look!

thk!!

$dir = "../images/albums/";
$album = $_POST['album'];
$add = $_POST['add'];
$b_dir = $dir.$album."/";
$aid = $_POST['aid'];

$thumb_path = "../images/albums/$album/thumb/";

if($add == 1){
  if (is_dir($b_dir)) {
    if ($dh = opendir($b_dir)) {
      $i = 1;
      while (($file = readdir($dh)) !== false) {
        $tes = explode(".", $file);
        $arr_tmp = explode(".",$file);
        $formato = array_pop($arr_tmp);
        if( "." == $file || ".." == $file){
          continue;
        } elseif($tes[1] == "db") {
          continue;
        }

        $full_path = "../images/albums/$album/full/";
        $normal_path = "../images/albums/$album/normal/";
        $thumb_path = "../images/albums/$album/thumb/";
        $file_pacth = "../images/albums/".$album."/".$file;

        // Instanciamos o objeto Upload
        $handle = new Upload($file_pacth);
        $handle->auto_create_dir = true;
        $handle->file_overwrite = true;
        $handle->file_auto_rename = false;
        $stamp_name = time();

        // Definimos as configurações desejadas da imagem normal
        $handle->image_resize            = true;
        $handle->image_ratio_y           = false;
        $handle->image_x                 = 460;
        $handle->image_y                 = 320;
        $handle->image_watermark         = '../images/watermark.png';
        $handle->image_watermark_x       = -10;
        $handle->image_watermark_y       = -10;
        $handle->file_new_name_body =    "$stamp_name";
        $handle->file_name_body_add = '_normal';
        $handle->image_ratio_crop = true;

        // Definimos a pasta para onde a imagem maior será armazenada
        $handle->Process($normal_path);
        $nome_da_imagem_normal = $handle->file_dst_name;
        $normal = $normal_path.$nome_da_imagem_normal;

        // Aqui nos devifimos nossas configurações de imagem do thumbs
        $handle->image_resize            = true;
        $handle->image_ratio_y           = false;
        $handle->image_x                 = 100;
        $handle->image_y                 = 75;
        $handle->image_contrast          = 10;
        $handle->jpeg_quality            = 100;
        $handle->file_new_name_body =    "$stamp_name";
        $handle->file_name_body_add = '_thumb';
        $handle->image_ratio_crop = true;

        // Definimos a pasta para onde a imagem thumbs será armazenada
        $handle->Process($thumb_path);
        $nome_da_imagem_thumb = $handle->file_dst_name;
        $thumb = $thumb_path.$nome_da_imagem_thumb;
        $i++;
      }
      closedir($dh);

      if ($handle->processed) {
        //$adiciona = "INSERT INTO csm_galeria_fotos (fid,aid,titulo,descricao,thumb,img,full) VALUES('','".$aid."','".$titulo."','".$desc."','".$thumb."','".$normal."','".$full."')";
        //mysql_query($adiciona) or die("Não Foi Possível Adicionar A Imagem!");
        echo 'Operação realizada com sucesso!';
        echo "$i".$file_pacth."";
      } else {
        // Em caso de erro listamos o erro abaixo
        echo 'Erro encontrado!';
        echo 'Erro: ' . $handle->error . '';
      }
    }
  }
}
Reply
Re: Files from a Folder new!
by colin, 16 years ago
You have no error? Sa basically, your script is stoping, and a white page is displayed in the browser?

You are probably running out of memory. Try to increase the memory for PHP, or else process your images in batches.Reply
Re: Files from a Folder new!
by PlaynoGames, 16 years ago
No, my script don't stop and show me a white page

if I have 100 pics in the folder, the class just crop and resize 50 or less

I using the verssion 0.24, I try use the 0.25

I already increase the memory, but doesn't work!

I will record a video of my problem and post here

see ya!Reply
Re: Files from a Folder new!
by Tom, 15 years, 4 months ago
I have similar problem. I have few pictures in a local folder and i want in a loop resize each of them and save to diferent folder.

I read all files in the array and make loop foreach. Script goes well if there are small pictures and not a lot. If in folder are big pictures and many pictures the time limit for the script execution is the problem.

Any idea for resolving this problem? Aby script exaple?

Thanks a lot. and sorry for my english :)Reply
Re: Files from a Folder new!
by colin, 15 years, 4 months ago
See this post for instance.Reply
nqept dktvqzip new!
by dchygrzk isjln, 15 years, 10 months ago
azdivt whigf hseu ntex prcsnvu cdjm flntReply
Re: Files from a Folder new!
by PlaynowGames, 16 years ago
I solve my problem from another way!

I just do two function for create the thumb pic and normal Pics

Now, I can create my thumb and normal pics!

Thanks by your suport!Reply