Mega Code Archive

 
Categories / Php / Graphics
 

Multiple Image upload - JPG & SWF thumbnail

<? If ($Submit<>"Next ->") { ?> <form name="form1" enctype="multipart/form-data" method="post" action="processing.php"> <p>Upload pictures<br> <br> <br> Picture index <input type="text" name="insid"> </p> <table border="0" cellspacing="0" cellpadding="0" width="323"> <tr> <td width="59">&nbsp;</td> <td width="264"> <b>picture</b></td> </tr> <tr> <td width="59">#1</td> <td width="264"> <input type="file" name="pic1" size="70" > </td> </tr> <tr> <td width="59">#2</td> <td width="264"> <input type="file" name="pic2" size="70" > </td> </tr> <tr> <td width="59">#3</td> <td width="264"> <input type="file" name="pic3" size="70" > </td> </tr> <tr> <td width="59">#4</td> <td width="264"> <input type="file" name="pic4" size="70" > </td> </tr> <tr> <td width="59">#5</td> <td width="264"> <input type="file" name="pic5" size="70" > </td> </tr> <tr> <td width="59">#6</td> <td width="264"> <input type="file" name="pic6" size="70" > </td> </tr> <tr> <td width="59">#7</td> <td width="264"> <input type="file" name="pic7" size="70" > </td> </tr> <tr> <td width="59">#8</td> <td width="264"> <input type="file" name="pic8" size="70" > </td> </tr> <tr> <td width="59">#9</td> <td width="264"> <input type="file" name="pic9" size="70" > </td> </tr> <tr> <td width="59">#10&nbsp;</td> <td width="264"> <input type="file" name="pic10" size="70" > </td> </tr> </table> <br> <br> <br> <br> <input type="reset" name="Submit4" value="Reset"> <input type="submit" name="Submit" value="Next -&gt;"> </form> <? } else { // Define Back string $back = <<<EOD <br> <form name="form_back" action="processing.php" method="post"> <input type="submit" name="Submit" value="<- BACK"> </form> EOD; // End Define Back string flush(); set_time_limit(0); $piccount=0; if (!(extension_loaded("gd"))) {echo "GD library not compiled or loaded into this server!<br> This script can not work without GD library!"; die; } if (!(extension_loaded("ming"))) {echo "MING library not compiled or loaded into this server!<br> This script can not work without MING library!"; die; } if (!(is_dir("data"))) {echo "Directory \"data\" not found!<br> Please create directory with name \"data\" and set 0777 permissions (uploaded files goes here)"; die; } if ($insid=="") { echo "Missing picture index".$back; die; } // MAIN LOOP for ($i=1;$i<11;$i++) { // execute code only for selected/browsed files $xpic="pic".$i; if (($$xpic<>"none") and ($$xpic<>"")) { //file type check $cert1 = "image/pjpeg"; //jpg $cert2 = "image/jpeg"; //jpg (for MAC) $xtype =$HTTP_POST_FILES[$xpic]['type']; if (($xtype <> $cert1) AND ($xtype <> $cert2)) {$log.= "<b>#$i Not allowed file type ! ($xtype)</b><br>";} else { //copy jpg pic to server $dest="data/pic".$insid."_".$i."big.jpg"; If (move_uploaded_file($$xpic, $dest)) {$log.=""; $piccount+=1;} else {$log.="$dest upload error!($$xpic)<br>";} // create SWF pic using MING lib functions $jpgx="data/pic".$insid."_".$i."big.jpg"; $b = new SWFBitmap($jpgx); //### create new FLASH bitmap object $pic = new SWFShape(); //### create new FLASH shape object $pic->setRightFill($pic->addFill($b)); $pic->drawLine($b->getWidth(), 0); $pic->drawLine(0, $b->getHeight()); $pic->drawLine(-$b->getWidth(), 0); $pic->drawLine(0, -$b->getHeight()); $big_h=$b->getHeight(); //### get uploaded pic heigh (for create jpg thumb) $big_w=$b->getWidth(); //### get uploaded pic with (for create jpg thumb) $movie = new SWFMovie(); $movie->setRate(50); //### Set movie frame rate //### set movie dimension as JPG dimension $movie->setDimension($b->getWidth(), $b->getHeight()); $movie->setBackground(0xff, 0xff, 0xff); $movie->add($pic); //### Add created shape object to curent frame $movie->nextFrame(); $swfx="data/pic".$insid."_".$i."big.swf"; $movie->save ($swfx); //### save this movi to hard/server chmod ($swfx, 0755); //### Change file permision $log.="#$i SWF pic created ($swfx)<br>"; // end create SWF pic // make thumbnail from uploaded pic using GD2 lib functions $scale_ratio=0.5; //### Thumbnail scale ratio $quality=90; //### Thumbnail quality $dest_w=$big_w*$scale_ratio; $dest_h=$big_h*$scale_ratio; $src_w=$big_w; $src_h=$big_h; $dest_jpgx="data/pic".$insid."_".$i."big.jpg"; $dest_t="data/pic".$insid."_".$i."thumb.jpg"; $in_jpg = imagecreatefromjpeg($dest_jpgx); $out_jpg = imagecreatetruecolor($dest_w,$dest_h); imagecopyresampled($out_jpg,$in_jpg,0,0,0,0,$dest_w,$dest_h,$src_w,$src_h); imagejpeg($out_jpg,$dest_t,$quality); //### save this thumb to hard/server imagedestroy($in_jpg); imagedestroy($out_jpg); // end make thumb from uploaded pic // create SWF thumb using MING lib function $jpgx1="data/pic".$insid."_".$i."thumb.jpg"; $b = new SWFBitmap($jpgx1); //### create new FLASH bitmap object $pic = new SWFShape(); //### create new FLASH shape object $pic->setRightFill($pic->addFill($b)); $pic->drawLine($b->getWidth(), 0); $pic->drawLine(0, $b->getHeight()); $pic->drawLine(-$b->getWidth(), 0); $pic->drawLine(0, -$b->getHeight()); $movie = new SWFMovie(); $movie->setRate(50); //### Set movie frame rate //### set movie dimension as JPG dimension $movie->setDimension($b->getWidth(), $b->getHeight()); $movie->setBackground(0xff, 0xff, 0xff); $movie->add($pic); //### Add created shape object to curent frame $movie->nextFrame(); $swfx="data/pic".$insid."_".$i."thumb.swf"; $movie->save ($swfx); //### save this movi to hard/server chmod ($swfx, 0755); //### Change file permision $log.="#$i SWF thumb created ($swfx)<br>"; // end create SWF thumb } //### end type check } //### end selected/browsed files } //### end MAIN LOOP echo $log."<br>"; echo "Number of updated picures: ".$piccount."<br>"; echo $back; } //### end submit ?>