كود:
<?php
$max_no_img = 10;
/////////////////////////////////////////////////////Create Thumbs Function
Function CreateThumb($file, $thename, $type, $new_width , $location){
list($width, $height) = getimagesize($file);
$new_height = floor( $height * ( $new_width / $width ) );
$image_p = imagecreatetruecolor($new_width , $new_height);
if ($type == "image/gif"){
$img = @imagecreatefromgif($file);
imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$location .= $thename;
imagegif($image_p, $location, 100);
} else if ($type == "image/png"){
$img = @imagecreatefrompng($file);
imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$location .= "$thename";
imagepng($image_p , $location, 100);
} else {
$img = @imagecreatefromjpeg($file);
imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$location .= "$thename";
imagejpeg($image_p , $location, 100);
}
}
/////////////////////////////////////////////Upload add the images
while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value)){ // this will check if any blank field is entered
$filename = $value; // filename stores the value or the file name
$NewName = substr($filename, 0, strrpos( $filename ,".")); // $NewName will store the file name without the extention
$NewName = str_replace(" ","-", $NewName); // Add - inplace of blank space in file name
$NewName .= rand(1000, 1000000); //add a random number to the filename
$NewName .= substr($filename, strrpos( $filename ,".") ); //add the original extention back to the file name
$images .= $NewName; //add the file name to a string to keepo track of the files that are uploaded
$images .= ","; //seperate each file with a comma
$add = "../Photos/FullView/$NewName"; // upload directory path is set
copy($_FILES[images][tmp_name][$key], $add); // upload the file to the server
$type1 = strtolower($_FILES[images][type][$key]);
CreateThumb($add, $NewName, $type1, 200, "../Photos/Thumbs/"); //origin image path //new filename //type of file // new directory for the created images
$NoImage = 0; //flag that there are new images has been added
}
$x++;
}
if ($NoImage == 0){
$images = substr($images, 0, -1);
}
///////////////////////////////////////////////////////////////////////////FORM
echo "<form method=\"post\" action=\"$PHP_SELF?action=add\" enctype=\"multipart/form-data\">
<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-style: solid; border-width: 1px; border-color: #333333; background-color: #EAEAE9;\" width=\"100%\">
<tr>
<td style=\"text-align: left; border-style: solid; border-width: 1px; border-color: #333333; color: #fff; background-color: #747474; text-align: center;\" colspan=\"2\"><strong>Add Stones</strong></td>
</tr>
<tr>
<td style=\"text-align: left; border-style: solid; border-width: 1px; border-color: #333333; background-color: #D8D7D6;\" width=\"30%\">Select an Album</td>
<td style=\"text-align: left; border-style: solid; border-width: 1px; border-color: #333333; background-color: #D8D7D6;\" width=\"70%\">
<select name=\"Catagory\">";
echo "<option value=\"0\">Please Select One...</option>";
while($CategoriesRows=mysql_fetch_array($SelectCategories)){
echo "<option value=\"".$CategoriesRows['id']."\">".$CategoriesRows['Title']."</option>";
}
mysql_free_result($SelectCategories);
unset($CategoriesRows);
echo "</select>
</td>
</tr>
<tr>
<td style=\"text-align: left; border-style: solid; border-width: 1px; border-color: #333333; background-color: #D8D7D6;\">Photo(s)</td>
<td style=\"text-align: left; border-style: solid; border-width: 1px; border-color: #333333; background-color: #D8D7D6;\">";
for($i=1; $i<= $max_no_img; $i++){
echo "<input type=\"file\" name=\"images[]\" class=\"bginput\" /><br />";
}
echo "</td>
</tr>
</table>
<br />
<input type=\"submit\" value=\" Add this stone \" />
</form>
<br /><br /><br />"
?>