用php上传照片

用php上传照片,php,html,mysqli,photos,Php,Html,Mysqli,Photos,我有一个照片库,我正试图创建这个社会网络,虽然我有上传部分的问题。我有一个预上传表单,它按照我想要的方式工作。有一个字段可用于浏览照片、添加标题以及选择要从数据库添加照片类别的库。表单action upload.php似乎是问题的根源,但它停止了 致命错误:第17行upload.php中超过了20秒的最大执行时间 这是上传部分——问题的根源 <?php require 'configphot.inc.php'; $photos_uploaded=$_FILES[photo_filename

我有一个照片库,我正试图创建这个社会网络,虽然我有上传部分的问题。我有一个预上传表单,它按照我想要的方式工作。有一个字段可用于浏览照片、添加标题以及选择要从数据库添加照片类别的库。表单action upload.php似乎是问题的根源,但它停止了

致命错误:第17行upload.php中超过了20秒的最大执行时间

这是上传部分——问题的根源

<?php
require 'configphot.inc.php';
$photos_uploaded=$_FILES[photo_filename];
$photo_caption=$_POST['photo_captions'];



$photo_type=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_type))
{
$final_result .= 'File' . ($counter +1) . 'is not a photo<br />';

}
else{
mysqli_query("
INSERT INTO gallery_photos (
photo_filename,
photo_caption,
photo_category
) VALUES (
'0',
'". $photo_captions[$counter] . "',
'". $_POST['category'] . "'
)
");

$new_id=mysqli_insert_id();

$filetype= $photos_uploaded['type'][$counter];
$extension = $known_photo_types[$filetype];
$filename = "$new_id.$extension";

mysqliquery ("
UPDATE gallery_photos SET
photo_filename= '$filename'
WHERE photo_id = '$new_id'


");

copy($photos_uploaded['tmp_name'][$counter], $images_dir . '/' . $filename);

$size = GetImageSize($images_dir . "/" . $filename);    

// Wide Image    
if($size[0] > $size[1])    
{     
 $thumbnail_width = 100;     
 $thumbnail_height = (int)(100 * $size[1] / $size[0]);     
}     

// Tall Image    
else    
{    
$thumbnail_width = (int)(100 * $size[0] / $size[1]);    
$thumbnail_height = 100;    
}

$gd_function_suffix= array (
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG', 
'image/gif' => 'GIF',
'image/bmp' => 'BMP',
'image/x-png' => 'PNG',
);

$function_suffix = $gd_function_suffix[$filetype]; //  get name suffix on basis of type
$function_to_read = 'ImageCreateFrom' . $function_suffix; // build function to read file
$function_to_write = 'Image'. $function_suffix; // function to write

$source_handle=$function_to_read($images_dir . '/' . $filename); //Read source file

if ($source_handle) {
$destination_handle = ImageCreateTrueColor($thumbnail_width,     $thumbnail_height); //creates blank image for thumbnail

ImageCopyResampled($destination_handle, $source_handle, 0,0,0,0,         $thumbnail_width, $thumbnail_height, $size[0], $size[1]); //image resize

$function_ti_write($destination_handle, $images_dir . '/tb_' . $filename);

}





}


}
}





?>
这里是预上传,它可以很好地工作,但只是用于上下文

<?php
require 'configphot.inc.php';



$_photo_upload_fields='';
$counter=1;

$nofields=(isset($_GET['number_of_fields']))?
(int) ($_GET['number_of_fields']):1;
$result = mysqli_query($link,"SELECT category_id, category_name FROM photo_category");

while($row = mysqli_fetch_array($result)) {  



$photo_category_list .="<option value =" .$row['category_id'] . ">" .  $row['category_name'] . "</option>";


}  



mysqli_free_result($result);


while($counter<=$nofields)
{
$photo_upload_fields .= <<<__HTML_END

<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>
__HTML_END;
$counter++;
}

//End output

echo <<<__HTML_END

<html>
<head>
<title> Upload photos here</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>

<!image fields here -->

$photo_upload_fields
<tr><td>
<input type ="submit" name="submit" value= "Add photos">
</td></tr>
</table>
</form>
</body>
</html>
__HTML_END;








?>
在php.ini文件中更改max_execution_time的值

如果无法更改PHP.INI,请在PHP文件中设置\u time\u limitseconds

max_execution_time = 300