0
我想用圖像和文件上傳文件。 我一直在嘗試修復它的歷史,並沒有設法得到它的工作。 (我是新手) PHP:php多個文件上傳與兩個輸入
$target_dir1 = "/Files/images";
$target_dir2 = "/Files/files";
$target_file1 = $target_dir1 . basename($_FILES["file"]["name"][0]);
$target_file2 = $target_dir2 . basename($_FILES["file"]["name"][1]);
$uploadOk = 1;
$fileType1 = pathinfo($target_file1,PATHINFO_EXTENSION);
$fileType2 = pathinfo($target_file2,PATHINFO_EXTENSION);
// Check if files already exists
if (file_exists($target_file1)) {
$msg .= "<script>document.write(\"<div class='alert alert-info alert-css'><a class='close' data-dismiss='alert' aria-label='close'>×</a><strong>Info!</strong> Sorry, file already exists.</div>\");</script>";
$uploadOk = 0;
}
if (file_exists($target_file2)) {
$msg .= "<script>document.write(\"<div class='alert alert-info alert-css'><a class='close' data-dismiss='alert' aria-label='close'>×</a><strong>Info!</strong> Sorry, file already exists.</div>\");</script>";
$uploadOk = 0;
}
// Check files size
if ($_FILES["file"]["size"][0] > 1500000) {
$msg .= "<script>document.write(\"<div class='alert alert-info alert-css'><a class='close' data-dismiss='alert' aria-label='close'>×</a><strong>Info!</strong> Sorry, your file is too large.</div>\");</script>";
$uploadOk= 0;
}
if ($_FILES["file"]["size"][1] > 1500000) {
$msg .= "<script>document.write(\"<div class='alert alert-info alert-css'><a class='close' data-dismiss='alert' aria-label='close'>×</a><strong>Info!</strong> Sorry, your file is too large.</div>\");</script>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "error";
} else {
if (move_uploaded_file($_FILES["file"]["tmp_name"][0], $target_file1)) {
$msg .= "<script>document.write(\"<div class='alert alert-info alert-css'><a class='close' data-dismiss='alert' aria-label='close'>×</a><strong>Info!</strong> The file ". basename($_FILES["file"]["name"][0]). " has been uploaded.</div>\");</script>";
}
}
if ($uploadOk == 0) {
echo "error1";
} else {
if (move_uploaded_file($_FILES["file"]["tmp_name"][1], $target_file2)) {
$msg .= "<script>document.write(\"<div class='alert alert-info alert-css'><a class='close' data-dismiss='alert' aria-label='close'>×</a><strong>Info!</strong> The file ". basename($_FILES["file"]["name"][1]). " has been uploaded.</div>\");</script>";
}
}
HTML:
<form class="col-lg-3" role="form" method='post' action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]."?page=Upload");?>" enctype="multipart/form-data">
<div class="form-group">
<label for="image">Image</label>
<input type="file" name="file[]" id="image">
</div>
<div class="form-group">
<label for="file">File</label>
<input type="file" name="file[]" id="file">
</div>
</form>
由於某種原因,這是行不通的。 我想要它做的是將兩個文件上傳到目錄。
更新
我後來想通,我必須要爲刪除斜線對$ TARGET_DIR面前,然後它的工作。
什麼_does不工作_請更具體地 – RiggsFolly
另外:你的表格是如何提交的? – fusion3k
它給我太大的錯誤或只是不上傳。 – DrevanTonder