我有一个具有两个输入文件的表单,一个是常规文件,第二个是多个文件,如果陈述中有两个,则在一个文件中
if (!empty($_FILES['logo']['name']) && !empty($_FILES['materials']['name']))
的
$_FILES['materials']
是倍数
我试图
json_encode()
$_FILES['materials']
但不起作用,它不能将第一个if传递给
is_uploaded_file()
/ php /
define('IMG_MAX_SIZE', 1024 * 1024 * 5);
if (isset($_POST['submit'])) {
$ex = ['jpg', 'png', 'jpeg', 'gif', 'bmp'];
if (!empty($_FILES['logo']['name']) && !empty($_FILES['materials']['name'])
) {
$matToStr = json_encode($_FILES['materials']);
if (is_uploaded_file($_FILES['logo']['tmp_name']) &&
is_uploaded_file($matToStr)) {
echo "in";
if ($_FILES['logo']['error'] == 0 && $_FILES['logo']['size'] <=
IMG_MAX_SIZE && $_FILES['materials']['error'] == 0 &&
$_FILES['materials']['size'] <= IMG_MAX_SIZE) {
echo "in2";
$logoInfo = pathinfo($_FILES['logo']['name']);
$materialsInfo = pathinfo($_FILES['materials']['name']);
if (in_array(strtolower($logoInfo['extension']), $ex) && in_array(strtolower($materialsInfo['extension']), $ex)) {
$logo = date('Y.m.d.H.i.s') . '-' . $_FILES['logo']['name'];
$materials = date('Y.m.d.H.i.s') . '-' . $_FILES['materials']['name'];
$_SESSION['logo'] = $logo;
$_SESSION['materials'] = $materials;
move_uploaded_file($_FILES['logo']['tmp_name'], 'uploads/' . $logo);
move_uploaded_file($_FILES['materials']['tmp_name'], 'uploads/' . $materials);
$pdo = DB();
$stmt = $pdo->prepare("INSERT INTO client_form_7 (client_id, logo, materials, websites) VALUES (:client_id, :logo, :materials, :websites)");
$stmt->bindParam("client_id", $user_id, PDO::PARAM_INT);
$stmt->bindParam("logo", $logo, PDO::PARAM_STR);
$stmt->bindParam("materials", $materials, PDO::PARAM_STR);
$stmt->bindParam("websites", $websites, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->rowCount() > 0) {
header('location: client-form-7.php?sm=תמונת הפרופיל עודכנה');
exit;
}
}
}
}
}
}
/ html /
<form action="" method="post" class="col s12" enctype="multipart/form-data">
<h4>7. קבצים וחומרים</h4>
<div class="row">
<div class="file-field input-field col s6">
<p>לוגו</p>
<div class="btn">
<span>בחר קובץ</span>
<input type="file" name="logo" id="logo">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
</div>
<div class="row">
<div class="file-field input-field col s6">
<p>צילומים וחומרים שעלולים להיות רלוונטי</p>
<div class="btn">
<span>בחר קובץ</span>
<input type="file" name="materials[]" id="materials" multiple>
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<input type="text" name="websites" id="websites" value="<?=old('websites')?>">
<label for="websites">אתרי אינטרנט שניתן למשוך משם חומרים</label>
</div>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="submit" class="btn left" value="העלה קבצים" name="submit">
</div>
</div>
</form>
我希望可以上传一个常规文件输入 和第二个像数组一样的第二个,因为我想稍后再获取