Warning: Unsupported style property aria-label. Did you mean ariaLabel?
in input (created by ForwardRef(InputBase))
in div (created by ForwardRef(InputBase))
in ForwardRef(InputBase) (created by WithStyles(ForwardRef(InputBase)))
in WithStyles(ForwardRef(InputBase)) (created by ForwardRef(Input))
in ForwardRef(Input) (created by WithStyles(ForwardRef(Input)))
如注释部分所建议,我已经更新了代码并立即使用PDO。我仍然有同样的错误。
我正在尝试将多个图像存储到数据库(phpmyadmin)。当我尝试上传时,出现错误UPDATED:
我的数据库:
我有一个名为image_upload的数据库,并且在数据库中有一个名为car_detailss的表,该表具有一个id(int11),car_name(varchar 255)和imageOfcar(longblob)。
这是我的图像详细信息:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'file.png' in 'field list'
根据评论部分的建议,我现在正在使用PDO 那是我的代码:(更新)
Array
(
[0] => Array
(
[name] => file.png
[type] => image/png
[tmp_name] => /opt/lampp/temp/phpJYyrQn
[error] => 0
[size] => 77776
)
[1] => Array
(
[name] => files.png
[type] => image/png
[tmp_name] => /opt/lampp/temp/phpXOLvzL
[error] => 0
[size] => 84710
)
)
如何解决我提到的错误(在顶部)?
答案 0 :(得分:1)
如评论部分所建议。我首先将代码更改为PDO,而不是插入没有任何反引号或“”的数据库,而是遵循注释部分的建议,并在将图像插入数据库时添加了反引号和“”。
$conn->exec( "INSERT INTO
car_details (
car_name ,
imageOfcar ) VALUES ('$carname', '$imagename')");
现在,我可以将图像插入数据库了。我也在这里更新了代码。
我的代码:
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="userfile[]" multiple="" />
<input type="submit" name="submit" value="upload" />
</form>
<?php
$servername="localhost";
$username="root";
$password = "";
$dbname="image_upload";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname",$username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// begin the transaction
$conn->beginTransaction();
$phpFileUploadErrors = array(
0 => "There is no error, the file uploaded with success",
1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini",
2 => "The upload file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
3 => "The upload file was only partially uploaded",
4 => "No file was uploaded",
6 => "Missing a temporary folder",
7 => "Failed to write file to disk.",
8 => "A php extension stopped the file upload"
);
if(isset($_FILES['userfile'])) {
$file_array = reArrayFiles($_FILES['userfile']);
pre_r($file_array);
for($i=0;$i<count($file_array);$i++) {
$carname = $file_array[$i]["size"];
$tablename = "car_detailss";
$imagename = $file_array[$i]["name"];
$conn->exec( "INSERT INTO `car_detailss` (`car_name`, `imageOfcar`) VALUES ('$carname', '$imagename')");
}
}
$conn->commit();
echo "new records created succesfully";
} catch(PDOException $e) {
// roll back the transaction if something failed
$conn->rollback();
echo "Error: " . $e->getMessage();
}
$conn = null;
function reArrayFiles($file_post) {
$file_ary = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i = 0; $i < $file_count; $i++){
foreach($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
}
}
return $file_ary;
}
function pre_r($array) {
echo '<pre>';
print_r($array);
echo '</pre>';
}
?>
</body>
</html>