Reply to Re: How to process multiple images that are inside a folder?

Re: How to process multiple images that are inside a folder? new!
by Marcio Alves, 13 years, 1 month ago
Hi my friend

I am wanting to run a folder where the class contains several files sent via the form.

The uploaded file is a. Zip file containing multiple photos. Jpg inside.

I can do with that. Zip is sent, deleted and unpacked in the destination.

I'm just not able to put the unzipped files in the class.

See my code:

$diretorio = '/home/ceanorg/public_html/fotos/galeria/teste/';

//$files = array();

// Diretório atual
$d = dir('/home/ceanorg/public_html/fotos/galeria/teste/');

// Percorre todos os arquivos
while(false !== ($file = $d->read())){

  // Se o arquivo não é este arquivo, e não começa com "." ou "~", então guarde-o para exibição futura.
  if(($file{0} != '.') && ($file{0} != '~') ) {
    
    // Guarda o nome do arquivo e dados completos de uma chamada à stat()
    $files[$file] = stat($file);
  }
}

// Fecha o diretório
$d->close();   

//$files = array('/home/ceanorg/public_html/fotos/galeria/teste/006.jpg', '/home/ceanorg/public_html/fotos/galeria/teste/007.jpg', '/home/ceanorg/public_html/fotos/galeria/teste/008.jpg');
$files[$file] = array();

foreach ($files as $k => $l) {
  foreach ($l as $i => $v) {
    if (!array_key_exists($i, $files))
      $files[$i] = array();
    $files[$i][$k] = $v;
  }
}


foreach ($files as $file) {

  // we instanciate the class for each element of $file
  $handle = new Upload($file);

  // then we check if the file has been uploaded properly
  // in its *temporary* location in the server (often, it is /tmp)
  if ($handle->uploaded) {

    // now, we start the upload 'process'. That is, to copy the uploaded file
    // from its temporary location to the wanted location
    // It could be something like $handle->Process('/home/www/my_uploads/');
    $handle->image_resize            = true;
    $handle->image_ratio_y           = true;
    $handle->image_x                 = 100;
    $handle->Process($diretorio);
    
    // we check if everything went OK
    if ($handle->processed) {
      // everything was fine !
      echo '  file uploaded with success';
      echo '  ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB';
      echo '  link to the file just uploaded: ' . $handle->file_dst_name . '';
    } else {
      // one error occured
      echo '  file not uploaded to the wanted location';
      echo '  Error: ' . $handle->error . '';
    }

  } else {
    // if we're here, the upload file failed for some reasons
    // i.e. the server didn't receive the file
    echo '  file not uploaded on the server';
    echo '  Error: ' . $handle->error . '';
  }
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important