Modificare upload photo

Ai o întrebare legată de PHP? Incercăm să îi găsim soluţie. Sau poate doar vrei să publici un cod interesant.

Moderatori: Zamolxe, Moderatori

Nsilviu
Average Member
Mesaje: 136
Membru din: Dum Dec 21, 2008 10:18 pm
Contact:

Modificare upload photo

Mesajde Nsilviu » Lun Iun 04, 2012 9:49 pm

Salut..
Am si eu urmatorul cod

Cod: Selectaţi tot

<?php

$upload_image_limit = 6; // How many images you want to upload at once?
$upload_dir         = "img_anunturi/"; // default script location, use relative or absolute path
$upload_thumb       = "thumb_anunturi/";
$enable_thumbnails   = 1 ; // set 0 to disable thumbnail creation
$max_image_size      = 1024000 ; // max image size in bytes, default 1MB

##################### THUMBNAIL CREATER FROM GIF / JPG / PNG
   
function make_thumbnails($updir, $img){

   $thumbnail_width   = 80;
   $thumbnail_height   = 60;
   $thumb_preword      = "thumb_";

   $arr_image_details   = GetImageSize("$updir"."$img");
   $original_width      = $arr_image_details[0];
   $original_height   = $arr_image_details[1];

   if( $original_width > $original_height ){
      $new_width   = $thumbnail_width;
      $new_height   = intval($original_height*$new_width/$original_width);
   } else {
      $new_height   = $thumbnail_height;
      $new_width   = intval($original_width*$new_height/$original_height);
   }

   $dest_x = intval(($thumbnail_width - $new_width) / 2);
   $dest_y = intval(($thumbnail_height - $new_height) / 2);



   if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF";  }
   if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG";  }
   if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG";  }


   if( $imgt ) {
      $old_image   = $imgcreatefrom("$updir"."$img");
      $new_image   = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
      imageCopyResized($new_image,$old_image,$dest_x,       
      $dest_y,0,0,$new_width,$new_height,$original_width,$original_height);
      $imgt($new_image,"$updir"."$thumb_preword"."$img");
   }

}









################################# UPLOAD IMAGES
   $i = 0;
      foreach($_FILES as $k => $v){

         $img_type = "";

         ### $htmo .= "$k => $v<hr />";    ### print_r($_FILES);
         

         if( !$_FILES[$k]['error'] && preg_match("#^image/#i", $_FILES[$k]['type']) && $_FILES[$k]['size'] < $max_image_size ){

            $img_type = ($_FILES[$k]['type'] == "image/jpeg") ? ".jpg" : $img_type ;
            $img_type = ($_FILES[$k]['type'] == "image/gif") ? ".gif" : $img_type ;
            $img_type = ($_FILES[$k]['type'] == "image/png") ? ".png" : $img_type ;
                 
                $i++;
            $img_rname = 'test_'.$i.$img_type;
            $img_path = $upload_dir.$img_rname;

            copy( $_FILES[$k]['tmp_name'], $img_path );
            if($enable_thumbnails) make_thumbnails($upload_dir, $img_rname);
            $feedback .= "Image and thumbnail created $img_rname<br />";

         }
      }






############################### HTML FORM
   while($i++ < $upload_image_limit){
      $form_img .= '<label>Image '.$i.': </label> <input type="file" name="uplimg'.$i.'"><br />';
   }

   $htmo .= '
      <p>'.$feedback.'</p>
      <form method="post" enctype="multipart/form-data">
         '.$form_img.' <br />
         <input type="submit" value="Upload Images!" style="margin-left: 50px;" />
      </form>
      ';   

   echo $htmo;




Nu este facut de mine, ma intereseaza si pe mine cum as putea ca imaginile 'thumb' sa se uploadeze in alt director adica in variabila $upload_thumb...


ALT + F2
Scrii " Free the fish "
Apesi Enter.
Sistem de operare: Linux

EoKlaus
Average Member
Mesaje: 133
Membru din: Mie Apr 20, 2011 3:11 pm
Localitate: Grecia

Mesajde EoKlaus » Lun Iun 04, 2012 11:15 pm

Incearca sa modifici asta:

Cod: Selectaţi tot

if($enable_thumbnails) make_thumbnails($upload_dir, $img_rname);


cu asta:

Cod: Selectaţi tot

if($enable_thumbnails) make_thumbnails($upload_thumb, $img_rname);
Copilaria nu este de la nastere pana la o anumita varsta, iar la o anumita varsta copilul a crescut si ia toate lucrurile copilaresti si le pune la o parte. Copilaria este regatul unde nu moare nimeni.

Imagine
[img=http://klaus-blog.hi2.ro/fisiere/imagine.php]

Nsilviu
Average Member
Mesaje: 136
Membru din: Dum Dec 21, 2008 10:18 pm
Contact:

Mesajde Nsilviu » Mar Iun 05, 2012 7:59 pm

Warning: getimagesize(thumb_anunturi/test_1.jpg) [function.getimagesize]: failed to open stream: No such file or directory in D:\xampp\xampp\htdocs\masina\upl\upl.php on line 17

Warning: Division by zero in D:\xampp\xampp\htdocs\masina\upl\upl.php on line 26

Cam asa ceva afiseaza cand ii modific acea linie.
ALT + F2

Scrii " Free the fish "

Apesi Enter.

Sistem de operare: Linux

Nsilviu
Average Member
Mesaje: 136
Membru din: Dum Dec 21, 2008 10:18 pm
Contact:

Mesajde Nsilviu » Mar Iun 05, 2012 8:10 pm

Am reusit pana la urma am inteles cat de cat codul si miam dat seama cum...
Am modificat functia care redimensiona poza...
lina modificata este:

Cod: Selectaţi tot

$imgt($new_image,"thumb_anunturi/"."$thumb_preword"."$img");
ALT + F2

Scrii " Free the fish "

Apesi Enter.

Sistem de operare: Linux


Înapoi la “Cod PHP”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 34 vizitatori