여러 파일을 업로드 할 때 문제가 있습니다. 범주 드롭 다운 및 파일 세부 정보와 함께 데이터베이스에 삽입해야하는 설명 상자가 있습니다. 5 개의 업로드 상자가 화면에 표시됩니다.여러 파일 업로드에 대한 의견 포함
하나의 파일을 업로드하는 경우, 주석은 공백으로 표시되며, 범주는 항상 첫 번째 값으로 설정됩니다. 최종 업로드 주석 및 카테고리 상자가 모든 덮어 쓰기를 덮어 쓰는 것처럼 보이기도합니다. 카테고리와 코멘트가 다른 다섯 개의 파일을 업로드하여 테스트 한 결과, 모두 마지막 코멘트와 카테고리가 표시되었습니다.
스크립트의 문제를 볼 수는 있지만 업로드의 각 특정 인스턴스에 범주 또는 설명을 지정하는 방법을 알 수 없습니다.
도움을 주시면 감사하겠습니다.
<?php
$upload_dir = "training/trainingDocuments/";
$maxUploads = 5;
$msg = "Please select file(s) for uploading";
$errors = array();
if ($files = convert_files($_FILES["myTrainingFile"])) {
foreach($files as $i => $file) {
$fileName = $file["name"];
$tempName = $file["tmp_name"];
$fileSize = $file["size"];
$fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$blacklist = array('exe','php','jsp','js','bat','asp','aspx','com','dmg');
// $newPath = $upload_dir .$fileName;
$dateUploaded = time() . microtime();
if (in_array($fileExt, $blacklist)) {
$errors[$i] = "File type not allowed";
}
if (!is_uploaded_file($tempName)) {
//$errors[$i] = "Uploading ".$fileName." failed.";
}else{
echo '<h4>Uploading of :'.$fileName.' was a success.</h4>';
}
//if(file_exists($newPath)){
$name = pathinfo($fileName, PATHINFO_FILENAME);
$fileName = $name . '__' .uniqid(). '.' .$fileExt;
$newPath = $upload_dir .$fileName;
// }else{
//
// }
if (isset($errors[$i])) {
continue;
}
if (!move_uploaded_file($tempName, $newPath)) {
//$errors[$i] = "Uploading ".$fileName." failed.";
}else{
//echo 'File moved';
}
$comments = htmlentities(trim($_POST['comments']));
$category = htmlentities(trim($_POST['category']));
if($file['name'] != ""){
$training->uploadDocument($fileName, $category, $comments);
}
}
}
?>
<?php
function convert_files($files) {
if (is_array($files) && !empty($files["name"])) {
if (is_array($files["name"])) {
$merged = array();
foreach($files["name"] as $i => $name) {
$merged[] = array(
"name" => $name,
"type" => $files["type"][$i],
"size" => $files["size"][$i],
"error" => $files["error"][$i],
"tmp_name" => $files["tmp_name"][$i]
);
}
return $merged;
}
return array($files);
}
return false;
}
?>
편집 :이 작동하는 경우
<div id="uploadFormContainer">
<form id="uploadForm" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data">
<?php
$num = 0;
while($num < $maxUploads)
{?>
<div class="uploadFormE">
<label>File Category: </label>
<select name="category">
<option value="doc">Documents (pages, word, PDF etc)</option>
<option value="sheet">Spreadsheet</option>
<option value="vid">Video</option>
<option value="pres">Presentations</option>
<option value="img">Image</option>
<option value="quiz">Quiz</option>
<option value="other">Other</option>
</select>
</div>
<div class="uploadFormE">
<label>File Location: </label>
<input type="file" name="myTrainingFile[]" />
</div>
<div class="uploadFormE">
<label>Comments: </label>
<textarea class="GAH" name="comments"> </textarea>
</div>
<hr/>
<br />
<?php $num++;
}
?>
<input type="submit" value="Upload File(s)">
</form>
</div>
업로드 된 각 파일에 대한 의견과 카테고리가 필요합니까? – Maximus2012
@ Maximus2012 - 이상적입니다.범주는 절대적으로 필요하며 주석은 큰 시련은 아니지만 바람직 할 것입니다. – null