I’m trying to upload pictures into the database in a BLOB. Whenever I use my current script it puts the file path in the BLOB instead of the jpg file. I’ve tested it by changing blob to text.
This is what I currently get whenever I try to upload a picture:
C:\xamppv2\tmp\php249C.tmp
I’m currently using [‘tmp_name’] and I think the is the cause of this problem. I was wondering what I have to change.
Here is my code:
$tipe_file1 = $_FILES[‘image1’][‘tmp_name’];
$tipe_file2 = $_FILES[‘image2’][‘tmp_name’];
$tipe_file3 = $_FILES[‘image3’][‘tmp_name’];
$tipe_file4 = $_FILES[‘image4’][‘tmp_name’];
$prijs = $_POST[‘prijs’];
$naam = $_POST[‘fname’];
$beschrijving = $_POST[‘desc’];
$maat1 = $_POST[‘maat1’];
$maat2 = $_POST[‘maat2’];
$maat3 = $_POST[‘maat3’];
$maat4 = $_POST[‘maat4’];
$aMyUploads = array(); foreach ($_FILES as $aFile) { if(0 === $aFile['error']){ $newLocation = ''.$aFile['tmp_name']; if(0 === $aFile['error'] && (false !== move_uploaded_file($aFile['tmp_name'], $newLocation))){ $aMyUploads[] = $newLocation;
} else { $aMyUploads[] = ''; } } } $stmt = $conn->prepare("INSERT INTO `producten` (naam, beschrijving, prijs, maat1, maat2, maat3, maat4, image1, image2, image3, image4) VALUES (:naam, :beschrijving, :prijs, :maat1, :maat2, :maat3, :maat4, :image1, :image2, :image3, :image4)"); $stmt->execute(array(":naam"=>$naam, ":beschrijving"=>$beschrijving, ":prijs"=>$prijs, ":maat1"=>$maat1, ":maat2"=>$maat2, ":maat3"=>$maat3, ":maat4"=>$maat4, ":image1"=>$aMyUploads[0], ":image2"=>$aMyUploads[1], ":image3"=>$aMyUploads[2], ":image4"=>$aMyUploads[3]));