I am still struggling to get some files uploaded to a database as BLOB
data. I have 5 includes which allows the user to upload 5 files,
numbered accordingly. However, there are script errors. Duhh, why else
would I post? Well, here goes:
CODE
$adres = trim (htmlspecialcha rs($_POST["adres"]));
$verkocht = trim (htmlspecialcha rs($_POST["verkocht"]));
$form_descripti on1 = trim
(htmlspecialcha rs($_POST["form_descripti on1"]));
$form_descripti on2 = trim
(htmlspecialcha rs($_POST["form_descripti on2"]));
$form_descripti on3 = trim
(htmlspecialcha rs($_POST["form_descripti on3"]));
$form_descripti on4 = trim
(htmlspecialcha rs($_POST["form_descripti on4"]));
$form_descripti on5 = trim
(htmlspecialcha rs($_POST["form_descripti on5"]));
// store the file information to variables for easier access 1
$tmp_name1 = $_FILES['form_data1']['tmp_name'];
$type1 = $_FILES['form_data1']['type'];
$name1 = $_FILES['form_data1']['name'];
$size1 = $_FILES['form_data1']['size'];
// store the file information to variables for easier access 2
$tmp_name2 = $_FILES['form_data2']['tmp_name'];
$type2 = $_FILES['form_data2']['type'];
$name2 = $_FILES['form_data2']['name'];
$size2 = $_FILES['form_data2']['size'];
// store the file information to variables for easier access 3
$tmp_name3 = $_FILES['form_data3']['tmp_name'];
$type3 = $_FILES['form_data3']['type'];
$name3 = $_FILES['form_data3']['name'];
$size3 = $_FILES['form_data3']['size'];
// store the file information to variables for easier access 4
$tmp_name4 = $_FILES['form_data4']['tmp_name'];
$type4 = $_FILES['form_data4']['type'];
$name4 = $_FILES['form_data4']['name'];
$size4 = $_FILES['form_data4']['size'];
// store the file information to variables for easier access 5
$tmp_name5 = $_FILES['form_data5']['tmp_name'];
$type5 = $_FILES['form_data5']['type'];
$name5 = $_FILES['form_data5']['name'];
$size5 = $_FILES['form_data5']['size'];
// if the upload succeeded, the file will exist
if (file_exists($t mp_name1) && file_exists($tm p_name2) &&
file_exists($tm p_name3) && file_exists($tm p_name4) &&
file_exists($tm p_name5)) {
// check to make sure that it is an uploaded file and not a system file
if (is_uploaded_fi le($tmp_name1) && is_uploaded_fil e($tmp_name2) &&
is_uploaded_fil e($tmp_name3) && is_uploaded_fil e($tmp_name4) &&
is_uploaded_fil e($tmp_name5)) {
// open the file for a binary read
$file1 = fopen($tmp_name 1,'rb');
$file2 = fopen($tmp_name 2,'rb');
$file3 = fopen($tmp_name 3,'rb');
$file4 = fopen($tmp_name 4,'rb');
$file5 = fopen($tmp_name 5,'rb');
// read the file content into a variable
$data1 = fread($file1,fi lesize($tmp_nam e1));
$data2 = fread($file2,fi lesize($tmp_nam e2));
$data3 = fread($file3,fi lesize($tmp_nam e3));
$data4 = fread($file4,fi lesize($tmp_nam e4));
$data5 = fread($file5,fi lesize($tmp_nam e5));
// close the file
fclose($file1) && fclose ($file2) && fclose($file3) && fclose ($file4)
&& fclose ($file5);
// now we encode it and split it into acceptable length lines
$data1 = chunk_split(bas e64_encode($dat a1));
$data2 = chunk_split(bas e64_encode($dat a2));
$data3 = chunk_split(bas e64_encode($dat a3));
$data4 = chunk_split(bas e64_encode($dat a4));
$data5 = chunk_split(bas e64_encode($dat a5));
}
else {
print("<br><b>I s this thing working? At all?</b><br>\n");
}
}
else {
print("<br><b>N ope, not yet...</b><br>\n");
}
$query = "INSERT into $Tabelnaam (adres,verkocht ,
description1,bi n_data1,filenam e1,filesize1,fi letype1,
description2,bi n_data2,filenam e2,filesize2,fi letype2,
description3,bi n_data3,filenam e3,filesize3,fi letype3,
description4,bi n_data4,filenam e4,filesize4,fi letype4,
description5,bi n_data5,filenam e5,filesize5,fi letype5)
values
('$adres', '$verkocht',
'$form_descript ion1', '$data1', '$name1', '$size1', '$type1',
'$form_descript ion2', '$data2', '$name2', '$size2', '$type2',
'$form_descript ion3', '$data3', '$name3', '$size3', '$type3',
'$form_descript ion4', '$data4', '$name4', '$size4', '$type4',
'$form_descript ion5', '$data5', '$name5', '$size5', '$type5')";
$Opdracht = mysql_query($qu ery) or die(mysql_error ());
print ("De opdracht is:<br />$Opdracht<P>\n ");
if(mysql_affect ed_rows($Verbin ding) == 1)
{
print ("De opdracht is met succes uitgevoerd!<br> \n");
}
else
{
print ("De opdracht kon niet worden uitgevoerd!<br> \n");
}
mysql_close ($Verbinding);
And this is the returned error:
QUOTE
Nope, not yet...
De opdracht is:
1
De opdracht is met succes uitgevoerd!
What's wrong with checking if the file exists, because that is where
the error message seems to come from...
data. I have 5 includes which allows the user to upload 5 files,
numbered accordingly. However, there are script errors. Duhh, why else
would I post? Well, here goes:
CODE
$adres = trim (htmlspecialcha rs($_POST["adres"]));
$verkocht = trim (htmlspecialcha rs($_POST["verkocht"]));
$form_descripti on1 = trim
(htmlspecialcha rs($_POST["form_descripti on1"]));
$form_descripti on2 = trim
(htmlspecialcha rs($_POST["form_descripti on2"]));
$form_descripti on3 = trim
(htmlspecialcha rs($_POST["form_descripti on3"]));
$form_descripti on4 = trim
(htmlspecialcha rs($_POST["form_descripti on4"]));
$form_descripti on5 = trim
(htmlspecialcha rs($_POST["form_descripti on5"]));
// store the file information to variables for easier access 1
$tmp_name1 = $_FILES['form_data1']['tmp_name'];
$type1 = $_FILES['form_data1']['type'];
$name1 = $_FILES['form_data1']['name'];
$size1 = $_FILES['form_data1']['size'];
// store the file information to variables for easier access 2
$tmp_name2 = $_FILES['form_data2']['tmp_name'];
$type2 = $_FILES['form_data2']['type'];
$name2 = $_FILES['form_data2']['name'];
$size2 = $_FILES['form_data2']['size'];
// store the file information to variables for easier access 3
$tmp_name3 = $_FILES['form_data3']['tmp_name'];
$type3 = $_FILES['form_data3']['type'];
$name3 = $_FILES['form_data3']['name'];
$size3 = $_FILES['form_data3']['size'];
// store the file information to variables for easier access 4
$tmp_name4 = $_FILES['form_data4']['tmp_name'];
$type4 = $_FILES['form_data4']['type'];
$name4 = $_FILES['form_data4']['name'];
$size4 = $_FILES['form_data4']['size'];
// store the file information to variables for easier access 5
$tmp_name5 = $_FILES['form_data5']['tmp_name'];
$type5 = $_FILES['form_data5']['type'];
$name5 = $_FILES['form_data5']['name'];
$size5 = $_FILES['form_data5']['size'];
// if the upload succeeded, the file will exist
if (file_exists($t mp_name1) && file_exists($tm p_name2) &&
file_exists($tm p_name3) && file_exists($tm p_name4) &&
file_exists($tm p_name5)) {
// check to make sure that it is an uploaded file and not a system file
if (is_uploaded_fi le($tmp_name1) && is_uploaded_fil e($tmp_name2) &&
is_uploaded_fil e($tmp_name3) && is_uploaded_fil e($tmp_name4) &&
is_uploaded_fil e($tmp_name5)) {
// open the file for a binary read
$file1 = fopen($tmp_name 1,'rb');
$file2 = fopen($tmp_name 2,'rb');
$file3 = fopen($tmp_name 3,'rb');
$file4 = fopen($tmp_name 4,'rb');
$file5 = fopen($tmp_name 5,'rb');
// read the file content into a variable
$data1 = fread($file1,fi lesize($tmp_nam e1));
$data2 = fread($file2,fi lesize($tmp_nam e2));
$data3 = fread($file3,fi lesize($tmp_nam e3));
$data4 = fread($file4,fi lesize($tmp_nam e4));
$data5 = fread($file5,fi lesize($tmp_nam e5));
// close the file
fclose($file1) && fclose ($file2) && fclose($file3) && fclose ($file4)
&& fclose ($file5);
// now we encode it and split it into acceptable length lines
$data1 = chunk_split(bas e64_encode($dat a1));
$data2 = chunk_split(bas e64_encode($dat a2));
$data3 = chunk_split(bas e64_encode($dat a3));
$data4 = chunk_split(bas e64_encode($dat a4));
$data5 = chunk_split(bas e64_encode($dat a5));
}
else {
print("<br><b>I s this thing working? At all?</b><br>\n");
}
}
else {
print("<br><b>N ope, not yet...</b><br>\n");
}
$query = "INSERT into $Tabelnaam (adres,verkocht ,
description1,bi n_data1,filenam e1,filesize1,fi letype1,
description2,bi n_data2,filenam e2,filesize2,fi letype2,
description3,bi n_data3,filenam e3,filesize3,fi letype3,
description4,bi n_data4,filenam e4,filesize4,fi letype4,
description5,bi n_data5,filenam e5,filesize5,fi letype5)
values
('$adres', '$verkocht',
'$form_descript ion1', '$data1', '$name1', '$size1', '$type1',
'$form_descript ion2', '$data2', '$name2', '$size2', '$type2',
'$form_descript ion3', '$data3', '$name3', '$size3', '$type3',
'$form_descript ion4', '$data4', '$name4', '$size4', '$type4',
'$form_descript ion5', '$data5', '$name5', '$size5', '$type5')";
$Opdracht = mysql_query($qu ery) or die(mysql_error ());
print ("De opdracht is:<br />$Opdracht<P>\n ");
if(mysql_affect ed_rows($Verbin ding) == 1)
{
print ("De opdracht is met succes uitgevoerd!<br> \n");
}
else
{
print ("De opdracht kon niet worden uitgevoerd!<br> \n");
}
mysql_close ($Verbinding);
And this is the returned error:
QUOTE
Nope, not yet...
De opdracht is:
1
De opdracht is met succes uitgevoerd!
What's wrong with checking if the file exists, because that is where
the error message seems to come from...
Comment