我收到错误消息“无法访问此网站http://localhost/vue_php_app/index.php上的网页可能暂时关闭,或者已永久移动到新的网址。ERR_CONTENT_DECODING_FAILED” 当我尝试使用PHP将图像上传到MySQL数据库时。
许多人已经建议设置为“ zlib.output_compression = On”,PHP表单中的enctype设置为“ multipart / form-data”。不知道还有什么尝试,只想将图像引用获取到MySQL数据库中,然后就可以检索它。感谢您的帮助!
Index.php
<?php
include("config.php");
if(isset($_POST['but_upload'])){
$name = $_FILES['file']['name'];
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif");
// Check extension
if( in_array($imageFileType,$extensions_arr) ){
// Insert record
$query = "insert into images(name) values('".$name."')";
mysqli_query($con,$query);
// Upload file
move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$name);
}
}
?>
<form method="post" action="" enctype='multipart/form-data'>
<input type='file' name='file' />
<input type='submit' value='Save name' name='but_upload'>
</form>
Config.php
<?php
$host = "localhost";
$user = "*****";
$password = "*****";
$dbname = "photo_app";
$con = mysqli_connect($host, $user, $password, $dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
?>