Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件名不能为空上载图像时出错_Php_Html_String_Error Handling - Fatal编程技术网

Php 文件名不能为空上载图像时出错

Php 文件名不能为空上载图像时出错,php,html,string,error-handling,Php,Html,String,Error Handling,我在我的数据库中存储了2个图像。如果我一次上传两张图片,那么它的存储成功了。但是如果我只上传图片1,或者我上传图片2,或者我没有上传任何图片,那么我会收到这个警告 警告:文件\u get\u contents()[function.file get contents]:第24行C:\wamp\www\print\main.php中的文件名不能为空 我的代码是: <label for="certificate">Upload Scaned Document:</label

我在我的数据库中存储了2个图像。如果我一次上传两张图片,那么它的存储成功了。但是如果我只上传图片1,或者我上传图片2,或者我没有上传任何图片,那么我会收到这个警告

警告:文件\u get\u contents()[function.file get contents]:第24行C:\wamp\www\print\main.php中的文件名不能为空

我的代码是:

    <label for="certificate">Upload Scaned Document:</label>
     <input type="file"  name="image" /> 
                 OR
     <label for="certificate">Upload Scaned QR Code</label>
     <input type="file" name="QRimage"  />
就连我也试过这么做:

    if(isset($_FILES["image"]) && (!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0))

然后我就能克服这个警告

如果我尝试上传Image1

         Notice: Undefined variable: QRimageName in C:\wamp\www\print\main.php on line 59
         Notice: Undefined variable: QRimageData in C:\wamp\www\print\main.php on line 59
如果我尝试上传Image2的话

         Notice: Undefined variable: imageName in C:\wamp\www\print\main.php on line 59
         Notice: Undefined variable: imageData in C:\wamp\www\print\main.php on line 59
我受够了这个错误请帮我解决这个问题试试这个

$imageName = "";
$imageData = "";
$QRimageName = "";
$QRimageData = "";
if(!empty($_FILES["image"]["name"])){ 
    $imageName = mysql_real_escape_string($_FILES["image"]["name"]);
    $imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
}
if(!empty($_FILES["QRimage"]["name"])){
    $QRimageName = mysql_real_escape_string($_FILES["QRimage"]["name"]);
    $QRimageData = mysql_real_escape_string(file_get_contents($_FILES["QRimage"]["tmp_name"]));
}
         Notice: Undefined variable: imageName in C:\wamp\www\print\main.php on line 59
         Notice: Undefined variable: imageData in C:\wamp\www\print\main.php on line 59
$imageName = "";
$imageData = "";
$QRimageName = "";
$QRimageData = "";
if(!empty($_FILES["image"]["name"])){ 
    $imageName = mysql_real_escape_string($_FILES["image"]["name"]);
    $imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
}
if(!empty($_FILES["QRimage"]["name"])){
    $QRimageName = mysql_real_escape_string($_FILES["QRimage"]["name"]);
    $QRimageData = mysql_real_escape_string(file_get_contents($_FILES["QRimage"]["tmp_name"]));
}