douan6931 2011-05-07 22:11
浏览 125

通过网址在php上传图片

i have this form to upload images:

<form method="post" action="upld.php" name="insertForm"  enctype="multipart/form-data">
Image name:<br />
<input type="text" name="iname" /><br />
<input type="file" name="file" />
<input type="submit" name="upload" value="Upload" />

</form>

and here is the upld.php

<?php
$db_name = "DB_name";
$table_name = "tble";
$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db($db_name, $connection) or die(mysql_error());

if(isset($_POST['upload'])){

 if  (($_FILES["file"]["error"] > 0))
    {
echo "<h3> Error in File! </h3>";
    }
  else
    {
    if ((file_exists("images/" . $_FILES["file"]["name"])) )
      {
      echo "<h3> file not exsists!</h3>";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/" . $_FILES["file"]["name"]);

//$id=mysql_insert_id();
$time=strftime("%Y-%m-%d %H:%M:%S", time());
$img_name=$_POST['iname'];
$img=$_FILES["file"]["name"];
$sql="INSERT INTO $table_name VALUES('{$img}','{$time}','{$img_name}')";
$result=mysql_query($sql,$connection);
mysql_close($connection);
echo "<h3>uploaded successfully</h3>";
}
}
}
echo "<br><br><a href='GalleryAdmin.php'>GO back to Admin Gallery</a>
";
?> 

the problem is:

when i run it always say me file not exsist, acording to this if

 if ((file_exists("images/" . $_FILES["file"]["name"])) )
      {
      echo "<h3> file not exsists!</h3>";

i have the images folder with upld.php in the same folder

what would you guess is the problem?

  • 写回答

4条回答 默认 最新

  • doulai8128 2011-05-07 22:14
    关注

    I think you have a slight logical error

    file_exists("images/" . $_FILES["file"]["name"])
    

    Will return true if the file exists in the images folder (my guess would me if somebody already uploaded it). But, based on your log statement, what you want is

    !file_exists("images/" . $_FILES["file"]["name"])
    
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False