我在使用XAMPP中的php上传文件时遇到问题
我的代码是:
include 'header.html';
include 'header.php';
include 'debugging.php';
echo '<br />';
echo '<h1> Upload files</h>';
echo <<<_END
<br/>
<form method='post' action='FileUpload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='100' />
<input type='submit' value='Upload' />
<input type='hidden' name='submitted' value='1' />
</form>
<br/>
_END;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
if (isset($_POST['submitted'])) {
if ($_FILES && $_FILES['filename']['name']) {
$file_info = pathinfo($_FILES['filename']['name']);
$extension = $file_info['extension'];
include 'DO_Files.php';
$valid = DO_File::validExtension($extension);
echo '1';
if ($valid) {
echo '2';
$tmpName = $_FILES['filename']['tmp_name'];
$name = "Files//" . $_FILES['filename']['name'];
if (!move_uploaded_file($_FILES['filename']['tmp_name'], $name)) {
echo '3';
echo "<p>there was an error..</p>";
echo error_get_last();
} else {
echo '4';
$file = new DO_File();
$file->FileName = $name;
$file->FileSize = $_FILES['filename']['size'];
if ($file->save()) {
echo '5';
echo $file->FileName;
} else {
echo '6';
mysqli_error($file->dbc);
}
}
} else {
echo '7';
echo '<p>the file is not prompted</p>';}
} else {
echo '8';
echo 'no filee';
}
}
include 'footer.html';
我不知道它为什么不上传。它可以在远程服务器上运行,但是像XAMPP这样的本地服务器在
上显示错误 if (!move_uploaded_file($_FILES['filename']['tmp_name'], $name)) {
任何帮助?因为我没有说明如何将文件上传到loacl服务器
我创建了一个目录,权限很好。
答案 0 :(得分:0)
if (is_array($_FILES['filename']) && $_FILES['filename']['error'] == 0) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
$sourcePath = $_FILES['filename']['tmp_name'];
$targetPath = "Files//" . $_FILES['filename']['name'];
if (!is_dir('Files//')) {
mkdir('Files/', 0777, true);
}
if (move_uploaded_file($sourcePath, $targetPath)) {
echo $targetPath;
}
}
}