我无法上传图片 php 一切正常,但上传失败
i can not upload image php everything is ok but it failes uploading
一切正常,我可以将查询单独插入到我的数据库中,但它不会移动上传的文件
这是我的代码。如果您能在下面找到任何问题,请查看。
它检查了我的图像文件夹目录它是正确的目录带我到确切的文件夹。
upload_file 也在 php.ini
但还是不行。
<?php
$conn = mysqli_connect("localhost", "root", "HERE_IS_MYCORRECT_PASSWORD", "HERE_IS_MYCORRECT_DTABASE_NAME");
if($conn) {
echo "<p style='color:green;'>connected</p>";
}
else {
echo " connection failed";
}
if(isset($_POST['uploadfilesub'])){
$id = $_POST['id'];
$filename = $_FILES['uploadfile']['name'];
$filetmpname = $_FILES['uploadfile']['tmp_name'];
$folder = './Resources/style/images/' . $filename;
echo "<p>".$filename."</p>";
echo "<p>".$filetmpname."</p>";
$sql = "INSERT INTO product_images VALUES ($id,'$filename') ";
if(move_uploaded_file($filetmpname , $folder)){
echo "<p color='green'>moved</p>";
$qry = mysqli_query($conn, $sql);
if($qry){
echo "<p color='green'>Inserted into mysql</p>";
} else {
echo "<p color='red'>Failed to Insert</p>";
}
}
else {
echo "<p style='color:red;'>Failed to move</p>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="id">
<input type="file" name="uploadfile" />
<input type="submit" name="uploadfilesub" value="upload" />
</form>
</body>
</html>
据我所知,您的错误(关于特定的、提到的问题)非常简单:
$folder = './Resources/style/images/';
更改为:
$folder = './Resources/style/images/' . $filename;
只是 move_uploaded_file
需要完整的目标路径,而不仅仅是目标文件夹。
一切正常,我可以将查询单独插入到我的数据库中,但它不会移动上传的文件 这是我的代码。如果您能在下面找到任何问题,请查看。
它检查了我的图像文件夹目录它是正确的目录带我到确切的文件夹。
upload_file 也在 php.ini
但还是不行。
<?php
$conn = mysqli_connect("localhost", "root", "HERE_IS_MYCORRECT_PASSWORD", "HERE_IS_MYCORRECT_DTABASE_NAME");
if($conn) {
echo "<p style='color:green;'>connected</p>";
}
else {
echo " connection failed";
}
if(isset($_POST['uploadfilesub'])){
$id = $_POST['id'];
$filename = $_FILES['uploadfile']['name'];
$filetmpname = $_FILES['uploadfile']['tmp_name'];
$folder = './Resources/style/images/' . $filename;
echo "<p>".$filename."</p>";
echo "<p>".$filetmpname."</p>";
$sql = "INSERT INTO product_images VALUES ($id,'$filename') ";
if(move_uploaded_file($filetmpname , $folder)){
echo "<p color='green'>moved</p>";
$qry = mysqli_query($conn, $sql);
if($qry){
echo "<p color='green'>Inserted into mysql</p>";
} else {
echo "<p color='red'>Failed to Insert</p>";
}
}
else {
echo "<p style='color:red;'>Failed to move</p>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="id">
<input type="file" name="uploadfile" />
<input type="submit" name="uploadfilesub" value="upload" />
</form>
</body>
</html>
据我所知,您的错误(关于特定的、提到的问题)非常简单:
$folder = './Resources/style/images/';
更改为:
$folder = './Resources/style/images/' . $filename;
只是 move_uploaded_file
需要完整的目标路径,而不仅仅是目标文件夹。