图片批量上传成功后,如何将路径与其他字段一同插入数据库?

WBOY
Release: 2016-06-23 14:12:10
Original
1299 people have browsed it

上传 数据库 图片




图片批量上传



请选择要上传的文件




















小图
中图
大图
图片说明:



$destination_folder = "picture/";

if(!file_exists($destination_folder))
{
mkdir($destination_folder);
}

foreach ($_FILES["u_file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["u_file"]["tmp_name"][$key];
$name = $_FILES["u_file"]["name"][$key];
$uploadfile = $destination_folder.time().$name;
move_uploaded_file($tmp_name, $uploadfile);
echo '文件'.$name.'上传成功,图片路径:'.$uploadfile.'
';

}
}
?>




红色部分为三张图片上传成功后显示的图片路径
然后在图片说明里,输入说明文字,请问3张图片的路径如何连同输入的图片说明内容一起提交到数据库?
例如数据库为:picture,对应字段分别为picid,p_explain(图片说明),s_pic(小图路径),m_pic(中图路径),b_pic(大图路径)

回复讨论(解决方案)

...........
echo '文件'.$name.'上传成功,图片路径:'.$uploadfile.'
';
$arr[]=$uploadfile;
}
$sql="insert into picture values('','$_POST['wd']','$arr[0]','$arr[1]','$arr[2]')";
mysql_query($sql);

LZ你是想同时插入N条记录?

insert into tableName(AA, BB, CC) values(1, 1, 1),(2, 2, 2);
Copy after login

sql语句可以在foreach循环上传时拼接,成功后执行




图片批量上传



请选择要上传的文件




















小图
中图
大图
图片说明:



$destination_folder = "picture/";

if(!file_exists($destination_folder))
{
mkdir($destination_folder);
}

foreach ($_FILES["u_file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["u_file"]["tmp_name"][$key];
$name = $_FILES["u_file"]["name"][$key];
$uploadfile = $destination_folder.time().$name;
move_uploaded_file($tmp_name, $uploadfile);
echo '文件'.$name.'上传成功,图片路径:'.$uploadfile.'
';

}
}
?>




红色部分为三张图片上传成功后显示的图片路径
然后在图片说明里,输入说明文字,请问3张图片的路径如何连同输入的图片说明内容一起提交到数据库?
例如数据库为:picture,对应字段分别为picid,p_explain(图片说明),s_pic(小图路径),m_pic(中图路径),b_pic(大图路径)

...........
echo '文件'.$name.'上传成功,图片路径:'.$uploadfile.'
';
$arr[]=$uploadfile;
}
$sql="insert into picture values('','$_POST['wd']','$arr[0]','$arr[1]','$arr[2]')";
mysql_query($sql);

$arr得出的数组是不是有问题?
Array ( [0] => picture/13703303631.jpg )
Array ( [0] => picture/13703303631.jpg [1] =>picture/13703303632.jpg )
Array ( [0] => picture/13703303631.jpg [1] =>picture/13703303632.jpg [2] => picture/13703303633.jpg )

没有问题,你是在foreach 里面打印的,当然是那个结果。请仔细看 #1 的回复。

没有问题,你是在foreach 里面打印的,当然是那个结果。请仔细看 #1 的回复。

非常感谢你的解答,功能已实现。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
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!