上传图片文件名不能为空错误
Filename cannot be empty error while uploading image
我正在将 2 张图像存储到我的数据库中。如果我一次上传 2 张图片,则存储成功。但是如果尝试只上传 image1 或者如果我尝试上传 image2 或者如果我没有上传任何图像那么我会收到这个警告
Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in C:\wamp\www\print\main.php on line 24
我的代码是:
<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" />
php代码:
$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$QRimageName = mysql_real_escape_string($_FILES["QRimage"]["name"]);
$QRimageData = mysql_real_escape_string(file_get_contents($_FILES["QRimage"]["tmp_name"]));
即使我尝试了这一切:
if(isset($_FILES["image"]) && (!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0))
和
if((isset($_FILES["QRimage"]["size"])) && ($_FILES["QRimage"]["size"] > 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"]));
}
我正在将 2 张图像存储到我的数据库中。如果我一次上传 2 张图片,则存储成功。但是如果尝试只上传 image1 或者如果我尝试上传 image2 或者如果我没有上传任何图像那么我会收到这个警告
Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in C:\wamp\www\print\main.php on line 24
我的代码是:
<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" />
php代码:
$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$QRimageName = mysql_real_escape_string($_FILES["QRimage"]["name"]);
$QRimageData = mysql_real_escape_string(file_get_contents($_FILES["QRimage"]["tmp_name"]));
即使我尝试了这一切:
if(isset($_FILES["image"]) && (!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0))
和
if((isset($_FILES["QRimage"]["size"])) && ($_FILES["QRimage"]["size"] > 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"]));
}