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
The pictures added to the database from the page cannot be displayed
Change $filename to relative path or physical path
There may be errors in these places
There is no stored file (the picture does not exist)
The picture address is incorrect (see the console error report Message)
The data was not retrieved