程式码的第一行if($_FILES)判断使用者是否有上传档案
有设定过 if($_FILES != "null"),if($_FILES != null),if($_FILES !="")
亦设定过$_FILES['newsimg'][name],$_FILES['newsimg'][tmp_name]
以下是我的upload.php
if($_FILES){
$sql = "select no from news where title_tw='$title_tw' or
title_ch='$title_ch' order by no desc;";
$result = mysqli_fetch_array(mysqli_query($con, $sql));
$newsid = $result['no'];
$num = count($_FILES['newsimg']['name']);
for($i = 0 ; $i < $num ; $i++){
$imgname = $_FILES['newsimg']['name'][$i];
$patch = "../images/news/";
$sql = "insert into news_images (newsid,imgname,imgurl) values
('$newsid','$imgname','$patch')";
if(mysqli_query($con, $sql) and
move_uploaded_file($_FILES['newsimg']['tmp_name'][$i],
$patch.$_FILES['newsimg']['name'][$i]))
echo $imgname."上传完毕。<br />";
}
echo "图片均以上传成功。<br />";
}
另外这个表单接收文字讯息与上传档案
程式码中我先储存接收到的文字资料到news,在抓出该笔资料id
接着将id给要储存图片的news_images
感觉步骤不精简,query了好多次
请问是否有更好的办法取代这样的方式呢?