繁体   English   中英

用php上传照片

[英]Uploading photos with php

我有一个照片库,我正在尝试为这个社交网络创建,虽然我有上传部分的问题。 我有预上传表格,可以按照我的要求运作。 有一个字段可以浏览照片,添加标题并选择要添加照片的图库(类别来自数据库)。 表单操作(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的值

max_execution_time = 300

如果你不能改变PHP.INI,PHP文件中的set_time_limit(seconds)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM