我遇到了一个难题,并想知道是否有人能给我一个直接的答案.所以我使用PHP / MysqL构建了一个照片上传脚本.在脚本中,照片会重新调整大小,并在上传时给出临时名称.我用几张图片(文件大小220 KB | 960 x 720)测试了它,一切都运行得很好.然后我试图从我的数码相机上传几张照片(文件大小2.47 MB | 3000 x 4000),突然间我收到了这个错误:
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /PHP_parsers/photo_system.PHP on line 94
Warning: Cannot modify header information - headers already sent by (output started at /PHP_parsers/photo_system.PHP:94) in /PHP_parsers/photo_system.PHP on line 96
我检查了stackoverflow以查找具有类似问题的帖子并且发现了一个但是它似乎不适用于我正在经历的场景.
以下是“photo_system.PHP”的适用代码.我已经对有问题的第94和96行进行了评论.您可以给予任何帮助/想法,我将不胜感激!
<?PHP
if (isset($_FILES["photo"]["name"]) && isset($_POST["gallery"])){
$sql = "SELECT COUNT(id) FROM photos WHERE user='$log_username'";
$query = MysqLi_query($db_conx, $sql);
$row = MysqLi_fetch_row($query);
if($row[0] > 79){
header("location: ../message.PHP?msg=The system allows only 80 pictures total");
exit();
}
$gallery = preg_replace('#[^a-z 0-9,]#i', '', $_POST["gallery"]);
$fileName = $_FILES["photo"]["name"];
$fileTmpLoc = $_FILES["photo"]["tmp_name"];
$fileType = $_FILES["photo"]["type"];
$fileSize = $_FILES["photo"]["size"];
$fileErrorMsg = $_FILES["photo"]["error"];
$kaboom = explode(".", $fileName);
$fileExt = end($kaboom);
$db_file_name = date("DMjGisY")."".rand(1000,9999).".".$fileExt; // WedFeb272120452013RAND.jpg
list($width, $height) = getimagesize($fileTmpLoc); //Offending Line 94
if($width < 10 || $height < 10){
header("location: ../message.PHP?msg=ERROR: That image has no dimensions"); //Offending Line 96
exit();
}
if($fileSize > 4194304) {
header("location: ../message.PHP?msg=ERROR: Your image file was larger than 4mb");
exit();
} else if (!preg_match("/\.(gif|jpg|png)$/i", $fileName) ) {
header("location: ../message.PHP?msg=ERROR: Your image file was not jpg, gif or png type");
exit();
} else if ($fileErrorMsg == 1) {
header("location: ../message.PHP?msg=ERROR: An unkNown error occurred");
exit();
}
$moveResult = move_uploaded_file($fileTmpLoc, "../user/$log_username/$db_file_name");
if ($moveResult != true) {
header("location: ../message.PHP?msg=ERROR: File upload Failed");
exit();
}
include_once("../PHP_includes/image_resize.PHP");
$wmax = 800;
$hmax = 600;
if($width > $wmax || $height > $hmax){
$target_file = "../user/$log_username/$db_file_name";
$resized_file = "../user/$log_username/$db_file_name";
img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
}
$sql = "INSERT INTO photos(user, gallery, filename, uploaddate) VALUES ('$log_username','$gallery','$db_file_name',Now())";
$query = MysqLi_query($db_conx, $sql);
MysqLi_close($db_conx);
header("location: ../photos.PHP?u=$log_username");
exit();
}
?><?PHP
if (isset($_POST["delete"]) && $_POST["id"] != ""){
$id = preg_replace('#[^0-9]#', '', $_POST["id"]);
$query = MysqLi_query($db_conx, "SELECT user, filename FROM photos WHERE id='$id' LIMIT 1");
$row = MysqLi_fetch_row($query);
$user = $row[0];
$filename = $row[1];
if($user == $log_username){
$picurl = "../user/$log_username/$filename";
if (file_exists($picurl)) {
unlink($picurl);
$sql = "DELETE FROM photos WHERE id='$id' LIMIT 1";
$query = MysqLi_query($db_conx, $sql);
}
}
MysqLi_close($db_conx);
echo "deleted_ok";
exit();
}
?>
解决方法:
大家好我弄清楚问题是什么.希望这将有助于未来的人.所以我检查了我的PHPinfo(),发现upload_max_filesize只设置为2M.我将PHP.ini添加到违规文件的目录中并包含:
upload_max_filesize = 250M
post_max_size = 250M
max_execution_time = 300
date.timezone = "America/Los_Angeles"
我不得不添加date.timezone,因为我的系统不喜欢我没有定义它的事实.无论如何,这已经解决了这个问题.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。