gpt4 book ai didi

PHP move_uploaded_file() 问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:00:08 27 4
gpt4 key购买 nike

我有 PHP 脚本 (testupload.php):

<?php

error_reporting(E_ALL);
ini_set('log_errors',1);
ini_set('error_log','/root/work/inputs/log_file');

$target_path = "/work/inputs";

$target_path = $target_path . basename( $_FILES['frag3']['name']);
echo "Received File: " . $_FILES['frag3']['name'] . " and moving it to " . $target_path . "<br>";

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

以及调用它的 HTML 文件:

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form action = "http://localhost:8081/testupload.php" method="post" enctype="multipart/form-data">
<span>Value : </span><input type="text" name="Value" value="Hello world"/><br />
<span>Fragment File : </span><input type="file" name="frag3" /><br />
<input type="submit" value="Send"/>
</form>
</body>
</html>

但是,我不断收到回复:上传文件出错,请重试!

很明显 move_uploaded_file() 没有正常运行。另外,它实际上并没有移动文件。但是,我似乎无法诊断出问题。

我的第一个想法是该目录不可写。但是我对该文件夹的权限是 drwxrwxrwx(由 ls -l 确定)

此外,行:ini_set('error_log','/root/work/inputs/log_file');

似乎没有将日志文件写入该位置。

有没有人有这方面的经验?我如何诊断这里发生了什么?

我在这里几乎不知所措,所以非常感谢任何帮助。

我正在使用 OpenSUSE 11.2、Apache 2.2 和 PHP 5.3。

非常感谢,布雷特

最佳答案

你应该做 move_uploaded_file($_FILES['frag3']['tmp_name'], $target_path)

关于PHP move_uploaded_file() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7518741/

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