class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
But, I used the example 1 and returned the following error:
file not uploaded to the wanted location Error: copy_failed
This is my code in full:
$handle = new Upload('/home/ceanorg/public_html/fotos/galeria/teste/', 'pt_BR');
if ($handle->uploaded) {
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 100;
$handle->Process('/home/ceanorg/public_html/fotos/galeria/teste/');
// 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: ../../fotos/galeria/teste/' . $handle->file_dst_name . ' : ' . $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 . '';
}
In your example 2, if you deal with local files, do not use the foreach loop! The foreach loop is only for uploaded files.
But, I used the example 1 and returned the following error:
file not uploaded to the wanted location
Error: copy_failed
This is my code in full:
$handle = new Upload('/home/ceanorg/public_html/fotos/galeria/teste/', 'pt_BR'); if ($handle->uploaded) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 100; $handle->Process('/home/ceanorg/public_html/fotos/galeria/teste/'); // 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: ../../fotos/galeria/teste/' . $handle->file_dst_name . ' : ' . $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 . ''; }You probably have a permission issue.
:(
The error log can be seen in http://www.cean.org.br/error.txt
The error produced by the class can be seen in http://cean.org.br/adm/image/upload.php
You first get all your file names in an array, and then loop through it, instantiating the class each time with each file name.
$files = array('pic1.jpg', 'pic2.jpg', 'pic3.jpg'); foreach ($files as $file) { $handle = new Upload($file); if ($handle->uploaded) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 100; $handle->Process('destination_directory/'); } }In order to help more people that perhaps might have the same problem, post here my code to send pictures zipped:
$uploadcaminho='test'; $codigo='13'; // START UPLOAD .ZIP FILE print "VERIFICANDO ARQUIVOS ENVIADOS"; if ($uploadcaminho) { print "FOLDER DESTINATION (".$uploadcaminho.") [FOLDER - OK]"; } else { die('FOLDER DESTINATION - ERROR'); } if (is_numeric($codigo)) { print "CODE (".$codigo.")[CODE - OK]"; } else { die('CODE ERROR'); } if (!file_exists("/home/folder/".$uploadcaminho)) { mkdir("/home/folder/".$uploadcaminho, 0755); print "/home/folder/".$uploadcaminho." [FOLDER CREATED - OK]"; } else { print "/home/folder/".$uploadcaminho." [FOLDER EXISTing]"; } print "START UPLOAD FILES ..."; if ($_FILES['my_field']['error'] == 0) { move_uploaded_file($_FILES['my_field']['tmp_name'], "/home/folder/".$uploadcaminho."/".$my_field_name); rename("/home/folder/".$uploadcaminho."/".$my_field_name, "/home/folder/".$uploadcaminho."/".$codigo.".zip"); $my_field_name = $codigo.".zip"; } else { die("ERROr ".$_FILES['my_field']['error']); } // START UNZIP $zip = new ZipArchive(); $zip->open("/home/folder/$uploadcaminho/$my_field_name"); $zip->extractTo("/home/folder/$uploadcaminho"); $zip->close(); echo "FILE $my_field_name UNZIP SUCCESS"; //DEL UNZIP FILE unlink ("/home/folder/teste/$my_field_name"); echo "FILE $my_field_name DELETED WITH SUCESS!"; // ---------- MULTIPLE UPLOADS ---------- $diretorio = '/home/folder/teste/'; $ponteiro = opendir($diretorio); while ($nome_itens = readdir($ponteiro)) { $itens[] = $nome_itens; } sort($itens); foreach ($itens as $k) { if ($k!="." && $k!=".."){ if (is_dir($k)) { $pastas[]=$k; } else { $arquivos[]=$diretorio.'/'.$k; } } } foreach ($arquivos as $file) { $handle = new Upload($file); if ($handle->uploaded) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 100; $handle->Process($diretorio); if ($handle->processed) { echo ' file uploaded with success'; echo ' ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB'; echo ' link to the file just uploaded: "../../fotos/galeria/teste/' . $handle->file_dst_name . ' : ' . $handle->file_dst_name . ''; } else { echo ' file not uploaded to the wanted location'; echo ' Error: ' . $handle->error . ''; echo ' Log: ' . $handle->log . ''; } } else { echo ' file not uploaded on the server'; echo ' Error: ' . $handle->error . ''; echo ' Log: ' . $handle->log . ''; } }Thank you for contributing your code.
How to get the width of the image being sent and whether it is greater than XX pixels, reduce.
This example s not function:
if($handle->image_x > 800) { $handle->image_resize = true; $handle->image_ratio = true; $handle->image_x = 800; //width }