if(is_uploaded_file($_FILES['img']['tmp_name'])){
if(move_uploaded_file($_FILES['img']['tmp_name'], $target_name)){
//这就算上传成功了,插入数据库
if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('mysql_dbname', $link)) {
echo 'Could not select database';
exit;
}
$sql = 'insert into table_name(id, img_path) values(img_id, $target_name)';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not create table the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
mysql_free_result($result);
}
else{
echo "上传失败";
}
}
上传-移动到本地目录-把路径存放在数据库