search

Home  >  Q&A  >  body text

The image is uploaded and cannot be displayed after being added to the database.

addPro.php page
<tr>
<td align="right">Product picture</td>
<td>
<label for=" file">Please select:</label>
<input type="file" name="file" id="file" />
<!-- <a href=" javascript:void(0)" id="selectFileBtn">Add attachment</a>
<div id="attachList" class="clear"></div> -->
</td>
</tr>
checkaddPro.php page
<?php
header('content-type:text/html;charset =utf-8');
include_once('conn.php');



$GName=$_POST["pName"];
$CID=$_POST ["CID"];
$GPrice=$_POST["mPrice"];
// $GImage=$_FILES["file"];
$GContent=$_POST["pDesc"];

if($_FILES["file"]["error"])
{
echo $_FILES["file"]["error"];
}
else
{
//Control the type and size of uploaded files
if(($_FILES["file"]["type"]=="image/jpeg" || $_FILES["file"] ["type"]=="image/png") && $_FILES["file"]["size"]<1024000)
{
  //Find the location where the file is stored
            // $ filename = "./file/".date("YmdHis").$_FILES["file"]["name"];
$path='uploads';
//Prevent duplicate name overwriting
$uniName=md5(uniqid(microtime(true),true)).'.'.$ext;
//echo $uniName;exit;
//$filename=$path.'/'. $uniName;
$filename='http://localhost/G15190101/admin/'.$path.'/'.date("YmdHis").$_FILES["file"]["name"];


##// Convert the encoding format
$ FILENAME = iconv ("UTF-8", "GB2312", $ FILENAME);
                                                                                                                     use   using   using   using   using           through using ’ ’ s ’ through ’ s using ’ s ’ through ‐ ‐ ‐‐‐‐ if(file_exists($filename))
                 "
}
Else
{
// Save the file
Move_uploaded_file ($ _ files [" file "] [" tmp_name "], $ filename); / $sql="insert into goods values('','{$filename}')";
              $sql = "insert into goods(GName,CID,GPrice,GImage,GContent) values('$GName', '$CID','$GPrice','$filename','$GContent')";
mysql_query($sql);
$num = mysql_affected_rows();
if ($num>0 ) {
echo "<script>alert('Add product successfully');location='addPro.php';</script>";
      }else{
            echo "<script>alert('Add product Failed');location='addPro.php';</script>";
}
       }
    }
                                                                                                                                                          ) ;
}
}
?>


Test the image added from the page below, but the image is not added to the uploads folder

QQ图片20171024164712.png

The pictures added to the database from the page cannot be displayed

2674 days ago1572

reply all(2)I'll reply

  • nearest

    nearest2017-10-26 00:23:28

    Change $filename to relative path or physical path

    reply
    1
  • 路过

    路过2017-10-25 08:16:16

    There may be errors in these places

    1. There is no stored file (the picture does not exist)

    2. The picture address is incorrect (see the console error report Message)

    3. The data was not retrieved

    reply
    0
  • It's not saved to my local folder, but I can't write

    · 2017-10-25 19:22:00
  • Cancelreply