move_uploaded_file无法正常上传

时间:2017-03-02 23:21:44

标签: php

所以我有一个上传系统,有一个简单的上传按钮。 上传工作正常,并上传到服务器上为其指定的目录。 但是move_uploaded_file不起作用。 每次我上传它都不会取代现有文件而只是忽略它。

<?php
$fn = "uploads/firstImage/";
$content = ($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file!");
fputs($fp, $content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=changed.php\"/> \n";
?>

上传时分离php文件:

<?php
$target = "uploads/firstImage/";
$target = $target . $_FILES['uploaded']['name'];
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file '$target' has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file" ; }
?>

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

the php documentation says that move_uploaded_file receives two parameters.

move_uploaded_file ( string $filename , string $destination );

you are missing the destination