gpt4 book ai didi

php - 文件未上传并出现错误 "File is not uploaded please try again"?

转载 作者:太空宇宙 更新时间:2023-11-04 03:53:10 25 4
gpt4 key购买 nike

我是初学者,我正在尝试从这个 tutorial 将文件上传到 uploads/ 文件夹但是当我在提交后运行我的程序时它显示错误 上传文件时出错,请重试! 你能告诉我这里出了什么问题吗?

表单.php:

<html>
<head>
<title>Form image</title>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="post" name="changer">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" name="uploadedfile" accept="image/jpeg">
<input type="submit" value="Submit">
</form>
</body>
</html>

uploader .php

<?php
//where the file is going to be placed..
$target_path="uploads/";

$target_path=$target_path.basename($_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)){
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}

最佳答案

正确的代码是

move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)

你正在使用

move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)

这将不起作用,因为文件在上传开始后存储在临时文件夹中,并且在移动文件时它必须知道临时名称,以便文件可以从临时文件夹移动到服务器。

关于php - 文件未上传并出现错误 "File is not uploaded please try again"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23150298/

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