gpt4 book ai didi

PHP 上传系统未将文件从临时目录移动到指定目录

转载 作者:行者123 更新时间:2023-11-30 00:16:37 27 4
gpt4 key购买 nike

因此,我尝试使用 W3Schools 示例作为引用来创建一个基本的 PHP/MySQL 图片上传系统,但是我一生都无法弄清楚为什么上传的文件没有被复制到指定的目的地。

这是我的 PHP 代码:

$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$uploads_dir = 'img/houses';

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
$uploads_dir . $_FILES["file"]["name"]);
echo "Stored in: " . $uploads_dir . $_FILES["file"]["name"];
}
} else {
echo "Invalid file";
}

这是 HTML 上传表单:

<form action="uploadHousePic.php" method="post" enctype="multipart/form-data">
Image: <input type="file" name="file" id="file"/>
<br><br>
Price: &pound; <input type="text" name="Price">
<br><br>
Type of house: <input type="text" name="Type">
<br><br>
Location: <input type="text" name="Location">
<br><br>
Description: <textarea rows="6" cols="60" input type="text" name="Description"></textarea>
<br><br>
<input type="submit" value="Submit" />
</form>

最后,我在另一个 php 页面上有目标代码,其中将插入图片+信息:

<?php
// this is used to connect to the database on the mysql server called houselist
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();// if there is a problem with the connection and it can't connect it will display this error to the user.
}

$result = mysqli_query($con,"SELECT * FROM tbl_house_info");//this setups the query to be used in order to gather the data to be displayed on the page. it will select all the data from the tbl_house_page.

while($row = mysqli_fetch_array($result)) {//this then will run a loop and fetch all the results from the database in an array and display them in order row by row.
echo '<div class="housepost">';//this is used to add the format of the web page that was used.
echo '<img src="img/houses/', $row['Image'],'" width="270px" height="190px" alt="" />';// this line adds the image to the div and adds in the destination of the image, the image will have been placed here from the upload and now adding in the file name from the database it will display the full image on the page.
echo '<h2>' , '£' ,$row['Price'] , '</h2>' , '<p>'. $row['Type'] , '</p>' , '<p>' . $row['Location'] , '</p>' , '<p>' , $row['Description'] , '</p>';// this will then add some more formatting as well as displaying the other columns of data which are the price, type, location and destination on the web page to the user.
echo "</div>";
}
?>

任何帮助将不胜感激。这是我正在做的一个大学项目,所以我想尝试自己解决这个问题;但是当你和你的老师都找不到问题时,就出问题了......

谢谢:)

最佳答案

检查 php.ini 中的最大文件大小和最大帖子大小是否足够大! :)

file_uploads = On

upload_max_filesize = xxxM

post_max_size = xxxM

对于 70% 的人来说,这是错误的配置。

编辑:重新启动服务器(Xampp、apache、wampp 或任何其他):)

关于PHP 上传系统未将文件从临时目录移动到指定目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23607323/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com