Ich habe ein Formular, wo der Benutzer seine Informationen eingibt und die Möglichkeit hat, mehr als 1 Longblob-Datei (entweder ein Bild oder eine andere Datei wie PDF) einfügen, funktioniert die Einfügung noch nicht, aber Ich kann Datei manuell in MySQL einfügen und abrufen (Ansicht/Download), der Anhang wird in eine "Anhang" -Tabelle hochgeladen und in eine Spalte "Anhang" in der Kundentabelle, hier ist ein Code-Ausschnitt dessen, was erreicht wird :mehrere BLOB-Datei Einfügung PHP
<?php function insertFile_db($myFile,$conn,$tablename,$id){
$fileCount = count($myFile["name"]);
$sql="INSERT INTO Attachments (tableName,CustomerId,Name,File,Size,Type) ";
for ($i = 0; $i < $fileCount; $i++) {
$fileName=$myFile["name"][$i]; // Note : $myFile=$_FILES['Attachment']
$fileTmp_name=$myFile["tmp_name"][$i];
$fileType=$myFile["type"][$i];
$fileSize=$myFile["size"][$i];
//$fileContent = addslashes(file_get_contents($myFile['images']['tmp_name']));
$file=fopen($fileTmp_name,'r'); //'r' open for reading only, pts at the beginning of the file
$fileContent=fread($file,$fileSize);
fclose($file);
$fileContent = addslashes($fileContent);
if(!get_magic_quotes_gpc())
$fileName = addslashes($fileName);
if($i==($fileCount-1) && $i==0)
$sql.="VALUES ('".$tablename."', ".$id.", '".$fileName."','$fileContent','".$fileSize."','".$fileType."')" ;
else if($i!=($fileCount-1) && $i==0)
$sql.="VALUES ('".$tablename."', ".$id.", '".$fileName."','$fileContent','".$fileSize."','".$fileType."')," ;
else if($i==($fileCount-1) && $i!=0)
$sql.=" ('".$tablename."', ".$id.", '".$fileName."','$fileContent','".$fileSize."','".$fileType."')" ;
else
$sql.=" ('".$tablename."', ".$id.", '".$fileName."','$fileContent','".$fileSize."','".$fileType."')," ;
}
if(!$conn->query($sql))
return True;
return Flase;
} ?>
und ich bin Aufruf der Funktion:
if(isset($_FILES['Attachment']) && !empty($_FILES['Attachment']['name'][0])){
$last_id = $conn->insert_id;
$error=insertFile_db($_FILES['Attachment'],$conn,CONTNAME,$last_id);
if($error===True)
{$conn->close();header("location:/skylite/".CONTNAME."/Create?error=Internal error");exit();}
}
Jetzt bin ich foc Wenn ich sie in den Attachment-Tisch einfüge, würde ich mich über einige Tipps und Hilfe freuen!