此代码不会打印上传图像的临时名称,也不会上传Photo文件夹中的任何图片。但打印图像名称。它正确地工作其他计算机。问题出在哪儿?请帮我。我正在使用PHP版本5.6.20
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$destination = "Photo/".$_FILES['image']['name'];
$filename = $_FILES['image']['tmp_name'];
echo $destination;
echo "<br/>";
echo $filename;
echo "<br/>";
if (file_exists($destination))
echo "Sorry, file already exists.";
else
move_uploaded_file($filename, $destination);
$name=$_FILES['image']['name'];
$tmp_name=$_FILES['image']['tmp_name'];
echo $tmp_name;
}
?>
<form method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Choose Image</td>
<td><input type="file" name="image"/> </td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name="Description" rows="4" cols="40"/></textarea></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="submit_image" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:2)
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<?php
if(isset($_POST['submit_image']))
{
$destination = "Photo/".$_FILES['image']['name'];
$filename = $_FILES['image']['tmp_name'];
echo $destination;
echo "<br/>";
echo $filename;
echo "<br/>";
if (file_exists($destination))
echo "Sorry, file already exists.";
else
move_uploaded_file($filename, $destination);
$name=$_FILES['image']['name'];
$tmp_name=$_FILES['image']['tmp_name'];
echo $tmp_name;
}
?>
<form method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Choose Image</td>
<td><input type="file" name="image"/> </td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name="Description" rows="4" cols="40"/></textarea></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="submit_image" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
我尝试了这段代码,它对我有用。请给你的照片文件夹的读写权限 我认为这对你有用。
答案 1 :(得分:1)
您的代码工作正常,请查看照片/&#39;文件夹权限和tmp文件夹路径也是如此。例如:D:\ xampp \ tmp \ phpDCD9.tmp。
答案 2 :(得分:1)
您的代码完全适用于我的机器。我想您可能想要检查已存储上载文件的目录名Photo
。检查您的目标文件夹名称,您的编码和项目所在的已定义文件夹名称是相同的。
请发布您的error
或warning
消息,以便提供帮助。
答案 3 :(得分:0)
我认为这部分写得恰到好处,它会解决
if (file_exists($destination)){
echo "Sorry, file already exists.";
}else{
move_uploaded_file($filename, $destination);
$name=$_FILES['image']['name'];
$tmp_name=$_FILES['image']['tmp_name'];
echo $tmp_name;
}