此代码不会打印上传图像的临时名称,也不会上传my 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>发布于 2017-03-08 13:32:13
<!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>我尝试了这个代码,它对我来说是有效的。请给你的照片文件夹的读写权限,我想它会为你工作。
发布于 2017-03-08 13:55:01
您的代码运行正常,请检查'Photo/‘文件夹权限和临时文件夹路径。例如: D:\xampp\tmp\phpDCD9.tmp。
发布于 2017-03-08 13:56:00
你的代码在我的机器上运行得很好。我认为您可能想要检查存储上传文件的目录名Photo。检查您的目标文件夹名称,您的代码和项目所在的已定义文件夹名称是否相同。请张贴您的error或warning消息,以便帮助您。
https://stackoverflow.com/questions/42663547
复制相似问题