Hello All,
I want to tried out from here to create agallery system
but I have found fatal rerror
My error is:
Fatal error: Maximum execution time of 30 seconds exceeded in d:\www\ujjwal\upload.php on line 30
means in a while loop
MY preupload.php is
PHP Code:
<?php
include 'config.inc.php';
// initialization
$photo_upload_fields = '';
$counter = 1;
// If we want more fields, then use, preupload.php?number_of_fields=20
$number_of_fields = (isset($_GET['number_of_fields'])) ?
(int)($_GET['number_of_fields']) : 5;
// Firstly Lets build the Category List
$result = mysql_query('SELECT category_id,category_name FROM gallery_category');
while($row = mysql_fetch_array($result)) {
$photo_category_list ?><select name="a">
<option value="<?=$row[0]?>"><?=$row[1]?></option>
<?
}
mysql_free_result( $result );
// Lets build the Image Uploading fields
while($counter <= $number_of_fields) {
$photo_upload_fields ?>
<tr><td> Photo <?=$counter?>: <input name="photo_filename[]" type="file" />
</td></tr>
<tr><td> Caption: <textarea name="photo_caption[]" cols="30" rows="1"></textarea>
</td></tr> <br>
<?
$counter++;
}
?>
// Final Output
<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<form enctype="multipart/form-data"
action="upload.php" method="post"
name="upload_form">
<table width="90%" border="0"
align="center" style="width: 90%;">
<tr><td>
Select Category
<select name="category">
<? $photo_category_list ?>
</select>
</td></tr>
<!-Insert the image fields here -->
<input type="text" name="photo_captions" value="">
<? $photo_upload_fields ?>
<tr><td>
<input type="submit" name="submit"
value="Add Photos" />
</td></tr>
</table>
</form>
</body>
</html>
My upload.php is
PHP Code:
<?// Fetch the image array sent by preupload.php
include 'config.inc.php';?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="../img/banner2.jpg" border="0" vspace="0" hspace="0" name="banner"></td>
</tr>
<tr>
<td valign=top width=16% class="menu">
<? //include_once("../menu2.php" ); ?>
</td>
<td width="*%" valign=top>
<?
// include the database specific information
//include_once("../inc/db.php" );
// make a connection to the rrc database
//dbConnect();
$images_dir = 'photos';
// Fetch the image array sent by preuploaed.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the image caption array
$photo_captions = $_POST['photo_captions'];
$photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);
while($counter <= count($photos_uploaded) ) {
if($photos_uploaded['size'][$counter] > 0) {
if(!array_key_exists($photos_uploaded['type'][$counter], $photo_types)) {
$result_final .= 'File ' . ($counter + 1) . ' is not a photo<br />';
} else {
// Great the file is an image, we will add this file
}
}
}
$query = "INSERT INTO gallery_photos (photo_filename, photo_caption, photo_category) VALUES ('0','" . $photo_captions[$counter] . "','" . $_POST['category'] . "')";
mysql_query($query);
$new_id = mysql_insert_id(); // New Id generated
// Get the filetype of the uploaded file
$filetype = $photos_uploaded['type'][$counter];
// Get the extension for the new name
$extension = $known_photo_types[$filetype];
// Generate a new name
$filename = "$new_id.$extension";
// let's update the filename now
$query = "UPDATE gallery_photos SET photo_filename = '$filename' WHERE photo_id = '$new_id'";
mysql_query($query);
copy($photos_uploaded['tmp_name'][$counter], $images_dir . '/' . $filename);
$size = GetImageSize($images_dir . "/" . $filename);
// Settings
$Config_tbwidth_wide = 100; // width of wide image
$Config_tbheight_wide = 75; // height of wide image
$Config_tbwidth_tall = 75; // width of tall image
$Config_tbheight_tall = 100; // height of tall image
// The code
if($size[0] > $size[1])
{
$thumbnail_width = $Config_tbwidth_wide;
$thumbnail_height = (int)($Config_tbwidth_wide * $size[1] / $size[0]);
if($thumbnail_height > $Config_tbheight_wide)
{
$thumbnail_height = $Config_tbheight_wide;
$thumbnail_width = (int)($Config_tbheight_wide * $size[0] / $size[1]);
}
}
else
{
$thumbnail_width = (int)($Config_tbheight_tall * $size[0] / $size[1]);
$thumbnail_height = $Config_tbheight_tall;
if($thumbnail_width > $Config_tbwidth_tall)
{
$thumbnail_width = $Config_tbwidth_tall;
$thumbnail_height = (int)($Config_tbwidth_tall * $size[1] / $size[0]);
}
}
$gd_function_suffix = array (
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'GIF',
'image/bmp' => 'WBMP',
'image/x-png' => 'PNG'
);
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = 'ImageCreateFrom' . $function_suffix;
$function_to_write = 'Image' . $function_suffix;
// Read the source file
$source_handle = $function_to_read($images_dir . '/' . $filename);
if ($source_handle) {
// Let's create a blank image for the thumbnail
$destination_handle =
ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
// Now we resize it
ImageCopyResampled($destination_handle, $source_handle,
0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
}
// Let's save the thumbnail
$function_to_write($destination_handle, $images_dir . '/tb_' . $filename);
?>
</td>
</tr>
</table>
//<?// include_once("../footer.php" ); ?>
Yes i have using one image from my desktop and the 4 places are empty.
Plz guide me what is my wrong of this script(which i have getting from site point)
Bookmarks