我在带有文字输入的表单上有一个图片上传按钮,但设计用于检查,调整大小和上传文件的脚本仅用于一次上传。
有没有办法可以使用带有以下代码的foreach()将每个文件提供给此脚本?
if (($_FILES['file']['type'] != 'image/jpeg') && ($_FILES['file']['type'] != 'image/jpg') && ($_FILES['file']['type'] != 'image/pjpeg')) {
echo "<script>alert('Images Must be in jpg format and under 2 Mb');\n";
echo sprintf("window.location='add.php'");
echo "</script>";
include('no-ad-footer.php');
} else {
chdir('admin/photos');
require_once('upload.php');
chdir('../../');
if ($up->ValidateUpload()) {
$node = new sqlNode();
$node->table = "photos";
$node->push("int","TypeID",$_POST['TypeID']);
$node->push("int","ListingID",$ListingID);
$node->push("text","Location",$new_name);
$node->push("int","POrder",$_POST['POrder']);
$node->push("defined","DateofUpload","NOW()");
if(($result = $mysql->insert($node)) === false)
die('Unable to push photo details into table photos line 38');
} else {
echo "<font color='red'>Unable to upload image</font>";
}
}
答案 0 :(得分:0)
没试过,但这应该有效:
$ftypelist = array('image/jpeg', 'image/jpg', 'image/pjpeg');
foreach($_FILES as $file){
if(in_array($file[type], $ftypelist){
echo "<script>alert('Images Must be in jpg format and under 2 Mb');\n";
echo sprintf("window.location='add.php'");
echo "</script>";
include('no-ad-footer.php');
} else {
chdir('admin/photos');
require_once('upload.php');
chdir('../../');
if ($up->ValidateUpload()) {
$node = new sqlNode();
$node->table = "photos";
$node->push("int","TypeID",$_POST['TypeID']);
$node->push("int","ListingID",$ListingID);
$node->push("text","Location",$new_name);
$node->push("int","POrder",$_POST['POrder']);
$node->push("defined","DateofUpload","NOW()");
if(($result = $mysql->insert($node)) === false)
die('Unable to push photo details into table photos line 38');
} else {
echo "<font color='red'>Unable to upload image</font>";
}
}
}