开发者

Uploading file Link in PHP

Sir, I want image uploading system for my users. I want that image must be uploaded in IMAGE folder and also its location link suppose to be copied in my Mysql database table. The problem is that image is uploaded in IMAGE folder in dir but in php MYSQL table its link does't get uploaded or copied.

Following are the scripts, Kindly Help to solve this:

Form Page:

<form action="UplaodGallery_script.php" method="post" enctype="multipart/form-data" name="form" id="form">
                <table width="414" height="78" border="0" align="center" cellpadding="0">
                  <tr>
                    <td width="111" height="15">Upload Photo :</td>
                    <td width="297"><label for="file"></label>
  开发者_C百科                    <input type="file" name="file" id="file"></td>
                  </tr>
                  <tr>
                    <td>Description :</td>
                    <td><label for="desc"></label>
                      <input type="text" name="desc" id="desc"></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td><p>
                      <input type="submit" name="button" id="button" value="Submit">
                    </p></td>
                  </tr>
                </table>
              </form>

UplaodGallery_script.php Page Code

<?php require_once('Connections/conne.php'); ?>
<?php

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }


    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);


      }
    }

else
  {
  echo "Invalid file";
  }


$path="upload/" . $_FILES["file"]["name"];
$desc=$_POST["desc"];

mysql_select_db("$database_conne"); 
mysql_query("INSERT INTO photo ('desc', 'photopath') VALUES ('$desc','$path')");

mysql_close ($conne);
?> 


Heyup,

It looks to me like the problem is in the mysql_query("INSERT INTO photo ('desc', 'photopath') VALUES ('$desc','$path')"); code.

May you try:

mysql_query("INSERT INTO photo (`desc`, `photopath`) VALUES ('$desc','$path')");

and see what happens? I put in backticks around the column names, that should solve the problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜