i am trying to store 2 images in my database . when i upload 2 images then both are storing successfully but when in try to upload single image then its giving undefined error for un-uploaded image. where i am wrong ?
My code is:
<label for="certificate">Upload Scaned Document:</label>
<input type="file" id="uploadImage" name="image" />
<label for="certificate">Upload Scaned QR Code</label>
<input type="file" name="QRimage" id="File2" />
And php code is
if((!empty($_FILES["image"])) && ($_FILES['image']['error'] == 0)) {
$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$imageType = mysql_real_escape_string($_FILES["image"]["type"]);
}
if((!empty($_FILES["QRimage"])) && ($_FILES['QRimage']['error'] == 0)) {
$QRimageName = mysql_real_escape_string($_FILES["QRimage"]["name"]);
$QRimageData = mysql_real_escape_string(file_get_contents($_FILES["QRimage"]["tmp_name"]));
}
Try this
$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"]));
}
Check with isset() like
if((isset($_FILES["image"]["size"]) &&
($_FILES["image"]["size"] > 0))
{
}
if((isset($_FILES["QRimage"]["size"]) &&
($_FILES["QRimage"]["size"] > 0))
{
$QRimageName = mysql_real_escape_string($_FILES["QRimage"]["name"]);
$QRimageData = mysql_real_escape_string(file_get_contents($_FILES["QRimage"]["tmp_name"]));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With