Learning & Integrating web technology and code help directory

How to use PHP & Multiple Upload and Multiple Resize to MySQL

No comments
How to use PHP & Multiple Upload and Multiple Resize to MySQL The guideline/example scripts how to using PHP and GD , Multiple Upload and Multiple Resize to MySQL
Example
php-multiple_resize_mysql1.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <form name="form1" method="post" action="php_multiple_resize_mysql2.php" enctype="multipart/form-data">  
  7. <input type="file" name="fileUpload[]"><br>  
  8. <input type="file" name="fileUpload[]"><br>  
  9. <input type="file" name="fileUpload[]"><br>  
  10. <input type="file" name="fileUpload[]"><br>  
  11. <input type="file" name="fileUpload[]"><br>  
  12. <input name="btnSubmit" type="submit" value="Submit">  
  13. </form>  
  14. </body>  
  15. </html>  
php-multiple_resize_mysql2.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)  
  8. {  
  9. if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")  
  10. {  
  11. $images = $_FILES["fileUpload"]["tmp_name"][$i];  
  12. $new_images = "thumbnails_".$_FILES["fileUpload"]["name"][$i];  
  13. copy($_FILES["fileUpload"]["tmp_name"][$i],"MyResize/".$_FILES["fileUpload"]["name"][$i]);  
  14. $width=100; //*** Fix Width & Heigh (Autu caculate) ***//  
  15. $size=GetimageSize($images);  
  16. $height=round($width*$size[1]/$size[0]);  
  17. $images_orig = ImageCreateFromJPEG($images);  
  18. $photoX = ImagesX($images_orig);  
  19. $photoY = ImagesY($images_orig);  
  20. $images_fin = ImageCreateTrueColor($width$height);  
  21. ImageCopyResampled($images_fin$images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX$photoY);  
  22. ImageJPEG($images_fin,"MyResize/".$new_images);  
  23. ImageDestroy($images_orig);  
  24. ImageDestroy($images_fin);  
  25.   
  26. echo "Resize Successful.<br>";  
  27.   
  28. //*** Insert Record ***//  
  29. $objConnect = mysql_connect("localhost","root","root"or die(mysql_error());  
  30. $objDB = mysql_select_db("mydatabase");  
  31. $strSQL = "INSERT INTO files ";  
  32. $strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"][$i]."')";  
  33. $objQuery = mysql_query($strSQL);  
  34. }  
  35. }  
  36.   
  37. ?>  
  38. <a href="php_multiple_resize_mysql3.php">View file</a>  
  39. </body>  
  40. </html>  
php-multiple_resize_mysql3.php

Create a php file and save to path root-path/myphp/
Screenshot
PHP & Multiple Upload and Multiple Resize to MySQL
PHP & Multiple Upload and Multiple Resize to MySQL

No comments :

Post a Comment