繁体   English   中英

使用PHP Mysql上传图像

[英]Image Upload Using PHP Mysql

此代码不会打印上载图像的临时名称,也不会在我的照片文件夹中上载任何图片。 但打印图像名称。 它可以正常工作在其他计算机上。 问题出在哪儿? 请帮我。 我正在使用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>
<!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>

我尝试了这段代码,它为我工作。 请授予您的照片文件夹的读写权限,我认为它将适合您。

您的代码工作正常,也请检查“照片/”文件夹权限和tmp文件夹路径。 例如:D:\\ xampp \\ tmp \\ phpDCD9.tmp。

您的代码在我的机器上运行正常。 我认为您可能想检查目录名称Photo ,其中已存储上传文件的目录。 检查您的目标文件夹名称客栈,您的项目所在的编码和定义的文件夹名称是否相同。 请张贴您的errorwarning消息,以便于帮助。

我认为这部分将像这样正确编写,它将解决

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM