-1
여기에 하나의 파일을 데이터베이스에 업로드하고 longblob을 사용했습니다.이 코드를 변경하여 동일한 ID로 여러 파일을 데이터베이스에 업로드 할 수 있으며 다운로드 옵션에서 동일한 ID에 대해 둘 이상의 업로드 된 파일을 다운로드 할 수 있습니까? . 아무도 나를 도울 수 있습니까? 다중 이미지 업로드이 코드를 변경하여 여러 파일을 업로드하려면 어떻게해야합니까?
if(isset($_FILES['uploaded_file'])) {
// Make sure the file was sent without errors
if($_FILES['uploaded_file']['error'] == 0) {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', '12345', 'documentksrsac');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Gather all required data
//$project_name = $_POST["pname"];
//$project_name = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['project_name']));
// $project_name =real_escape_string(['uploaded_file']['project_name']);
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']));
$size = intval($_FILES['uploaded_file']['size']);
// Create the SQL query
$query = "
INSERT INTO `fileupload1` (
`name`, `mime`, `size`, `data`
)
VALUES (
'{$name}', '{$mime}', {$size}, '{$data}'
)";
// Execute the query
$result = $dbLink->query($query);
// Check if it was successfull
if($result) {
echo 'Success! Your file was successfully added!';
}
else {
echo 'Error! Failed to insert the file'
. "<pre>{$dbLink->error}</pre>";
}
}
else {
echo 'An error accured while the file was being uploaded. '
. 'Error code: '. intval($_FILES['uploaded_file']['error']);
}
// Close the mysql connection
$dbLink->close();
}
else {
echo 'Error! A file was not sent!';
}
// close connection
//mysqli_close($link);
?>