我已经在这个上传php的文件上工作了一段时间,但我无法让它工作。当我点击上传时,'if'语句变为false。
如果有人能指出我哪里出错了,那就太好了。
<?php
$name = $_FILES["file"]["name"];
$tmp_name = $_FILES["file"]["tmp_name"];
if(isset($name)) {
if(!empty($name)) {
$location = "uploads/";
if(move_uploaded_file($tmp_name, $location . $name)) {
echo "Uploaded";
} else {
echo $location . $name;
echo "<br>";
echo $tmp_name;
}
} else {
echo "Please choose a file!";
}
}
?>
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
答案 0 :(得分:3)
你的$ locatIon可能是错的,尝试传递一个绝对路径(你的例子中的路径是相对于当前工作目录的,并且它可能是不可写的)
答案 1 :(得分:0)
这有效,
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>
<form action="getfile.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>
</body>
</html>
<强> getfile.php 强>
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")
?>
</body>
</html>