警告:getimagesize()[function.getimagesize]:文件名不能为空警告消息? [英] Warning: getimagesize() [function.getimagesize]: Filename cannot be empty warning message?

查看:362
本文介绍了警告:getimagesize()[function.getimagesize]:文件名不能为空警告消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到最近,我一直在使用一些PHP将照片上传到网站.但是突然之间,它开始触发各种错误消息.

Up until recently I've been using some PHP to upload photos to a site. But suddenly it's started triggering all sorts of error messages.

我使用的表单可以在运行时运行以下代码:

I use a form that on action runs the following code:

$uploaddir = "../../user_content/photo/";
$allowed_ext = array("jpeg", "jpg", "gif", "png");

    if(isset($_POST["submit"])) {
        $file_temp = $_FILES['file']['tmp_name'];   
        $info = getimagesize($file_temp);
    } else {
        print "File not sent to server succesfully!";
        exit;
    }

表单的文件上传部分包含以下元素:

The file upload part of the form has the following elements:

<input name="file" type="file" class="photo_file_upload">

用于上传的提交按钮具有以下属性:

The submit button for uploading has the following attributes:

<button type="submit" name="submit" class="photo_upload">Upload</button>

但是,每当我运行此命令时,我总会收到以下警告:

But whenever I run this, I always get the following warning:

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in (upload PHP file) on line 10

(第10行是此部分:$ info = getimagesize($ file_temp);)

(line 10 is this part: $info = getimagesize($file_temp);)

任何人都知道这是什么原因吗?

Anyone have any ideas on what the cause of this is?

推荐答案

您检查了表单是否已提交,但没有检查文件是否已发送.在某些情况下,可以提交表单,但不会发送文件(即文件大小大于配置中的文件大小限制).

You checked if the form was submitted, but didn't check if the file was sent. In some cases, a form could be submitted but the file will not sent (i.e. file size is bigger then file size limit in config).

使用此:

if(isset($_POST["submit"]) && isset($_FILES['file'])) {
    $file_temp = $_FILES['file']['tmp_name'];   
    $info = getimagesize($file_temp);
} else {
    print "File not sent to server succesfully!";
    exit;
}

您会看到&& isset($ _ FILES ['file'])是新的

或者您可以扩展它

if(isset($_POST["submit"]) && isset($_FILES['file'])) {
    $file_temp = $_FILES['file']['tmp_name'];   
    $info = getimagesize($file_temp);
} 
elseif(isset($_POST["submit"]) && !isset($_FILES['file'])) {
    print "Form was submitted but file wasn't send";
    exit;
}
else {
    print "Form wasn't submitted!";
    exit;
}

这篇关于警告:getimagesize()[function.getimagesize]:文件名不能为空警告消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆