我的上传脚本出现问题。它将照片的相册上传到users文件夹,它还为每个文件夹创建一个缩略图,并将引用插入到数据库中。离线测试时(使用XAMPP)一切都上传得很好。然而,在线似乎只适用于几个文件。任何更大的东西都会失败,甚至不会运行任何东西(它会在按钮处输出消息,就好像什么都没有运行一样)。
起初我认为这是PHP.ini文件,但我为我正在测试的专辑设置了正确的vaules。我检查了服务器上的phpinfo()以确保应用了值。我已经搞乱了设置以增加帖子大小等所以我知道这不是问题。想不出它还有什么,请帮忙!
PHP.ini中
upload_max_filesize = 10M
post_max_size = 500M
max_input_time = 60
max_file_uploads = 100
上传脚本
require_once '../includes/connect.php';
if($_GET) {
$username = $_GET['id'];
$result =mysqli_query($con, "SELECT acc_id FROM account WHERE username = '$username'");
$userinfo = mysqli_fetch_array($result);
$acc_id = $userinfo['acc_id'];
}
if(isset($_POST['sendfiles']))
{
$album_name = $_POST['label'];
$album_name = mysqli_real_escape_string($con, $album_name);
$sqlalbum = "INSERT INTO gallery_album (acc_id, user, title, date_created) VALUES ($acc_id, '$username', '$album_name', NOW())";
mysqli_query($con, $sqlalbum);
$album_id = mysqli_insert_id($con);
if(!is_dir( $_SERVER["DOCUMENT_ROOT"] . "/image/". $username ."/" . $album_name)) {
mkdir( $_SERVER["DOCUMENT_ROOT"] . "/image/". $username ."/" . $album_name);
}
$uploaddir = $_SERVER["DOCUMENT_ROOT"] . "/image/". $username ."/" . $album_name;
foreach ($_FILES['photos']['name'] as $name => $value)
{
$nameofile = stripslashes($_FILES['photos']['name'][$name]);
$extension = pathinfo($nameofile, PATHINFO_EXTENSION);
$newfilename = uniqid() . "." . $extension;
if (($extension != "jpg") && ($extension != "JPG") && ($extension != "jpeg") && ($extension != "JPEG") &&
($extension != "png") && ($extension != "PNG") && ($extension != "gif") && ($extension != "GIF") &&
($extension != "bmp") && ($extension != "BMP"))
{
//print error message
header('location: ../view/error');
}
else
{
$filename = $_FILES['photos']['name'][$name];
$source = $_FILES['photos']['tmp_name'][$name];
$target= $_SERVER["DOCUMENT_ROOT"] ."/image/". $username ."/". $album_name ."/". $newfilename;
move_uploaded_file($source, $target);
if(preg_match('/[.](jpg)|(JPG)$/', $filename)) {
$im = imagecreatefromjpeg($_SERVER["DOCUMENT_ROOT"] ."/image/". $username ."/". $album_name ."/". $newfilename);
} else if (preg_match('/[.](gif)|(GIF)$/', $filename)) {
$im = imagecreatefromgif($_SERVER["DOCUMENT_ROOT"] ."/image/". $username ."/". $album_name ."/". $newfilename);
} else if (preg_match('/[.](png)|(PNG)$/', $filename)) {
$im = imagecreatefrompng($_SERVER["DOCUMENT_ROOT"] ."/image/". $username ."/". $album_name ."/". $newfilename);
} else if (preg_match('/[.](bmp)|(BMP)$/', $filename)) {
header('location: ../view/error');
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = 400;
$ny = floor($oy * (400 / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
imagejpeg($nm, $_SERVER["DOCUMENT_ROOT"] ."/image/". $username ."/". $album_name ."/thumb". $newfilename);
$sqlimage = "INSERT INTO gallery_image (filename, album_id, acc_id, user, album_title, date_created) VALUES ('$newfilename', $album_id, $acc_id, '$username', '$album_name', NOW())";
mysqli_query($con, $sqlimage);
$image_id = mysqli_insert_id($con);
$sqlrel = "INSERT INTO gallery_relation (acc_id, album_id, image_id) VALUES ('$acc_id', '$album_id', '$image_id')";
if (!mysqli_query($con, $sqlrel)) {
die('Error: ' . mysqli_error($con));
}
}
}
$sqlalbum = "UPDATE gallery_album SET preview='$newfilename' WHERE album_id='$album_id'";
mysqli_query($con, $sqlalbum);
header('location: ../view/photos');
//echo "Images uploaded successfully";
//echo $acc_id . " ";
//echo $newfilename . " ";
//echo $newname;
} else {
echo "upload has failed";
}
编辑:以下是请求和响应标头
请求
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:9744316
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryWFXD7z91g1od2ZmU
Cookie:PHPSESSID=251c9c673446c0728aefb0b7b85ae4a8
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
响应
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:37
Content-Type:text/html
Date:Wed, 28 Jan 2015 02:19:56 GMT
Keep-Alive:timeout=5, max=100
Server:Apache
Vary:User-Agent,Accept-Encoding
X-Powered-By:PHP/5.2.17