//#####################################// // ---------- IMAGE UPLOAD ---------- // //#####################################// // we create an instance of the class, giving as argument the PHP object // corresponding to the file field from the form // All the uploads are accessible from the PHP object $_FILES $handle = new Upload($_FILES['my_field'], 'pl_PL'); // then we check if the file has been uploaded properly // in its *temporary* location in the server (often, it is /tmp) if ($handle->uploaded) { // yes, the file is on the server // below are some example settings which can be used if the uploaded file is an image. $handle->image_resize = true; $handle->image_ratio_y = false; $handle->image_ratio_x = false; $handle->image_x = 70; $handle->image_y = 70; // now, we start the upload 'process'. That is, to copy the uploaded file // from its temporary location to the wanted location ../.../admin/cfg.php // It could be something like $handle->Process('/home/www/my_uploads/'); $handle->Process('./zdj/'); // we check if everything went OK if ($handle->processed) { // everything was fine ! echo ' male: <a href="./zdj/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>'; } else { // one error occured } // we now process the image a second time, with some other settings $handle->image_resize = true; $handle->image_ratio_y = false; $handle->image_ratio_x = false; $handle->image_x = 300; $handle->image_y = 250; $handle->Process('./zdj/_duze/'); // we check if everything went OK if ($handle->processed) { // everything was fine ! echo ' DUZE: <a href="./zdj/_duze/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>'; } else { // one error occured } // we delete the temporary files $handle-> Clean(); } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file }
Ale! nie mogę pojąć w jaki sposób przerobić dodawanie zdjec w trybie multi (czyli 3zdjecia na raz) w sposób, aby również były zmieniane rozmiary na małe i duże z podziałem na katalogi, ktoś mądry kto zna się na PDO pomoże?
// ---------- MULTIPLE UPLOADS ---------- // as it is multiple uploads, we will parse the $_FILES array to reorganize it into $files foreach ($_FILES['my_field'] as $k => $l) { foreach ($l as $i => $v) { $files[$i][$k] = $v; } } // now we can loop through $files, and feed each element to the class 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->Process($dir_dest); // we check if everything went OK if ($handle->processed) { // everything was fine ! echo ' link to the file just uploaded: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; } else { // one error occured } } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file } } }