Upload i resize vise slika odjednom?

Upload i resize vise slika odjednom?

offline
  • Pridružio: 29 Jun 2007
  • Poruke: 51
  • Gde živiš: Nis

Zanima me kako mogu da odradim upload vise slika (konkretno 3) i njihov resize jedan na odredjenu dimenziju i jos jedan na drugu dimenziju, i sve to kroz jednu skriptu. Ja sam gledao i nasao neke skripte za upload jedne po jedne slike, ali nisam za vise odjednom, a to mi treba, i treba mi da dobijem nakon toga i njihove lokacije na serveru gde su uploadovane, znaci lokaciju svih 6 slika (3 vece i 3 manje) kako bih mogao da upisem posle pomocu druge skripte u bazu informacije o njihovoj lokaciji.

Ima li neko ovako nesto vec? Wink

Dopuna: 24 Jun 2008 15:44

Evo skripte koje koristim za upload jedne slike
<?php $idir = "images/";   // Path To Images Directory $tdir = "images/thumbs/";   // Path To Thumbnails Directory $twidth = "166";   // Maximum Width For Thumbnail Images $theight = "122";   // Maximum Height For Thumbnail Images if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?> <div id="apDiv14">   <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>?subpage=upload" enctype="multipart/form-data">    File:<br />    <input type="file" name="imagefile" class="form">    <br />    <br />   <input name="submit" type="submit" value="postavi sliku" class="form"> <input type="reset" value="resetuj" class="form">   </form></div> <?php } else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script   $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use   if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {     $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php     $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location     if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location       print 'Slika je uspesno postavljena.<br />';   // Was Able To Successfully Upload Image       $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From       $currwidth = imagesx($simg);   // Current Image Width       $currheight = imagesy($simg);   // Current Image Height       if ($currheight > $currwidth) {   // If Height Is Greater Than Width          $zoom = $twidth / $currheight;   // Length Ratio For Width          $newheight = $theight;   // Height Is Equal To Max Height          $newwidth = $currwidth * $zoom;   // Creates The New Width       } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)         $zoom = $twidth / $currwidth;   // Length Ratio For Height         $newwidth = $twidth;   // Width Is Equal To Max Width         $newheight = $currheight * $zoom;   // Creates The New Height       }       $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail       imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete       $palsize = ImageColorsTotal($simg);       for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image        $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used        ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use       }       imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)       imagejpeg($dimg, "$tdir" . $url);   // Saving The Image       imagedestroy($simg);   // Destroying The Temporary Image       imagedestroy($dimg);   // Destroying The Other Temporary Image       print 'Thumbnail je napravljen uspesno.'; // Resize successful       print "<br />images/thumbs/$url";       print "<br />images/$url";     } else {       print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed     }   } else {     print '<font color="#FF0000">Greska: Pogresna vrsta fajla za upload (mora da bude .jpg ili .jpeg. vas tip fajla je: ';   // Error Message If Filetype Is Wrong     print $file_ext;   // Show The Invalid File's Extention     print '.</font>';   } } ?>
E ja zelim ovako nesto da imam u browseru:

I da uploadujem izabrane slike na server, i tek ako su svi fajlovi validni (ako su slike a ne recimo php skripte ili slicno) da skripta prosledi njihove lokacije drugoj skripti tipa:
http://sajt/neka_skripta_gde_se_prosledjuje?prvavelika=OvdeAdresaPrveVelike&prvaMala=AdresaMaleSliceceZaPrvu&drugavelika=AdresaDrugeVelike... itd za sve 6 slike (posto imamo 3 male i tri vece)...
Nadam se da ste me skontali Smile[/code]

Dopuna: 24 Jun 2008 22:25

Malo izmenih skriptu Smile
<?php $idir = "images/";   // Path To Images Directory $tdir = "images/thumbs/";   // Path To Thumbnails Directory $twidth = "166";   // Maximum Width For Thumbnail Images $theight = "122";   // Maximum Height For Thumbnail Images if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?> <div id="apDiv14">   <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>?subpage=upload" enctype="multipart/form-data">    File:<br />    <input type="file" name="imagefile1" class="form">    <br />    <input type="file" name="imagefile2" class="form">    <br />    <input type="file" name="imagefile3" class="form">    <br />    <br />   <input name="submit" type="submit" value="postavi sliku" class="form"> <input type="reset" value="resetuj" class="form">   </form></div> <?php } else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {     for ($counterloop=1;$counterloop<=3;$counterloop++){    // Uploading/Resizing Script   $url = $_FILES["imagefile$counterloop"]['name'];   // Set $url To Equal The Filename For Later Use   if ($_FILES["imagefile$counterloop"]['type'] == "image/jpg" || $_FILES["imagefile$counterloop"]['type'] == "image/jpeg" || $_FILES["imagefile$counterloop"]['type'] == "image/pjpeg") {     $file_ext = strrchr($_FILES["imagefile$counterloop"]['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php     $copy = copy($_FILES["imagefile$counterloop"]['tmp_name'], "$idir" . $_FILES["imagefile$counterloop"]['name']);   // Move Image From Temporary Location To Permanent Location     if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location       print 'Slika je uspesno postavljena.<br />';   // Was Able To Successfully Upload Image       $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From       $currwidth = imagesx($simg);   // Current Image Width       $currheight = imagesy($simg);   // Current Image Height       if ($currheight > $currwidth) {   // If Height Is Greater Than Width          $zoom = $twidth / $currheight;   // Length Ratio For Width          $newheight = $theight;   // Height Is Equal To Max Height          $newwidth = $currwidth * $zoom;   // Creates The New Width       } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)         $zoom = $twidth / $currwidth;   // Length Ratio For Height         $newwidth = $twidth;   // Width Is Equal To Max Width         $newheight = $currheight * $zoom;   // Creates The New Height       }       $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail       imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete       $palsize = ImageColorsTotal($simg);       for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image        $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used        ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use       }       imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)       imagejpeg($dimg, "$tdir" . $url);   // Saving The Image       imagedestroy($simg);   // Destroying The Temporary Image       imagedestroy($dimg);   // Destroying The Other Temporary Image       print 'Thumbnail je napravljen uspesno.'; // Resize successful       print "<br />images/thumbs/$url";       print "<br />images/$url";     } else {       print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed     }   } else {     print '<font color="#FF0000">Greska: Pogresna vrsta fajla za upload (mora da bude .jpg ili .jpeg. vas tip fajla je: ';   // Error Message If Filetype Is Wrong     print $file_ext;   // Show The Invalid File's Extention     print '.</font>';   }   } } ?>

E sad, ova skripta uploaduje dobro ako izaberem za sve fajlove slike u formatu u kom treba, tj. u jpg formatu, medjuti, sta ako neko izabere recimo exe fajl ili nesto drugo sto ne bi trebalo, a meni treba da se proslede podaci o informaciji o lokaciji slika jedino ako sve prodje kako valja...

Dopuna: 24 Jun 2008 22:26

Zapravo, problem i nije problem Smile Resih ga Smile Heh Smile
Cimanje oko nicega Smile

Dopuna: 24 Jun 2008 22:28

Ubacim jednu promenjivu koja ce da bude logickog tipa i ako vrati jednom bar false vracam korisnika da opet unosi slike Smile
I tako dok se ne opameti i resi da unese sve kako valja Smile



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 916 korisnika na forumu :: 19 registrovanih, 5 sakrivenih i 892 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: dane007, darkojbn, dragoljub11987, Fog of War, goxin, havoc995, JOntra, kybonacci, Milos82, nemkea71, Nikolaa11, pein, Sir Budimir, slonic_tonic, Tas011, vaso1, vlad4, wizzardone, zlaya011