web 2.0

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

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

ShotDev Focus:
- PHP & GD (Multiple Upload and Multiple Resize to MySQL)

Example

php-multiple_resize_mysql1.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form name="form1" method="post" action="php_multiple_resize_mysql2.php" enctype="multipart/form-data">
<input type="file" name="fileUpload[]"><br>
<input type="file" name="fileUpload[]"><br>
<input type="file" name="fileUpload[]"><br>
<input type="file" name="fileUpload[]"><br>
<input type="file" name="fileUpload[]"><br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>

php-multiple_resize_mysql2.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$new_images = "thumbnails_".$_FILES["fileUpload"]["name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"MyResize/".$_FILES["fileUpload"]["name"][$i]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);

echo "Resize Successful.<br>";

//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"][$i]."')";
$objQuery = mysql_query($strSQL);
}
}

?>
<a href="php_multiple_resize_mysql3.php">View file</a>
</body>
</html>

php-multiple_resize_mysql3.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM files";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="200" border="1">
<tr>
<th width="50"> <div align="center">Files ID </div></th>
<th width="150"> <div align="center">Thumbnails </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["FilesID"];?></div></td>
<td><center><a href="MyResize/<?=$objResult["FilesName"];?>">
<img src="MyResize/<?=$objResult["Thumbnails"];?>" border="0"></a></center></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<br>
<a href="php_multiple_resize_mysql1.php">Upload Image</a>
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php-multiple_resize_mysql1.php

Screenshot

PHP & Multiple Upload and Multiple Resize to MySQL

PHP & Multiple Upload and Multiple Resize to MySQL

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

One Response to “How to use PHP & Multiple Upload and Multiple Resize to MySQL”

  1. 3statewide…

Leave a Reply

You must be logged in to post a comment.