一切正常我可以单独将查询插入我的数据库,但它不会移动上传的文件这是我的代码。如果您能在下面找到任何问题,请查看。它检查了我的图像文件夹目录它是正确的目录将我带到确切的文件夹。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> <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>
1 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
据我所知,您的错误(关于特定的,提到的问题)非常简单:
$folder = './Resources/style/images/';
改成:
$folder = './Resources/style/images/' . $filename;
只move_uploaded_file
需要完整的目标路径,而不仅仅是目标文件夹。
- 1 回答
- 0 关注
- 84 浏览
添加回答
举报
0/150
提交
取消