The image is uploaded and cannot be displayed after being added to the database.
2017-10-24 17:25:55
0
2
1501

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

reply all(2)
nearest

Change $filename to relative path or physical path

路过

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 It's not saved to my local folder, but I can't write
    author 2017-10-25 19:22:00
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!