2011-05-14 48 views
0

先生,我想为我的用户图像上传系统。 我希望该图像必须上传到IMAGE文件夹中,并且它的位置链接假设将被复制到我的Mysql数据库表中。 问题是该图像上传到IMAGE文件夹中的目录,但在PHP MYSQL表中其链接不上传或复制。上传文件链接在PHP

这些脚本如下,请帮助解决这个:

表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> 
         <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页代码

<?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); 
?> 
+0

首先进行基本调试。什么*得到*复制到数据库中?新的行看起来像什么? – 2011-05-14 13:23:29

+2

另外,你的代码容易受到SQL注入的攻击:http://www.php.net/manual/en/security.database.sql-injection.php – 2011-05-14 13:24:16

+0

添加一个id字段会使它更容易在稍后删除照片,加上使用mysql_real_escape_string($ desc)是必须的! – 2011-05-14 13:31:12

回答

0

Heyup,

在我看来,问题出在mysql_query("INSERT INTO photo ('desc', 'photopath') VALUES ('$desc','$path')");的代码中。

愿你试试:

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

,并看看会发生什么?我在列名周围反过来,这应该可以解决问题