[英]PHP uploading form problems
我在使用php上傳表單時遇到問題,我過去曾創建過這樣的頁面,但由於某種原因,這個頁面似乎正在播放,我希望我只是錯過了這么簡單的東西。 我正在嘗試創建和上傳表單以上傳Wav,rar,zip和txt文件,並在其他所有內容上返回錯誤。
如果我嘗試上傳與這些文件無關的文件,則會顯示錯誤,但是如果我嘗試上傳wav或zip文件,則此文件不起作用,我不會收到任何錯誤報告,但是如果我要上傳.txt文件似乎正常工作。
我的HTML代碼是;
<form action="<?php echo $site_url; ?>upload.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="upload" id="upload" value="upload" />
<label for="invoice"><strong>Select Invoice Number</strong></label>
<select name="invoice" <?php if (array_key_exists('invoice', $add_product_errors)) echo ' class="error"'; ?>>
<?php while($row = mysqli_fetch_array($r)){ ?>
<option value="<?php echo $row[0] ; ?>"
<?php if (isset($_POST['invoice']) && ($_POST['invoice'] == $row[0]) ) echo ' selected="selected"';
echo ">" .$row[0]. "</option>\n"; ?>
<?php } ?>
</select><?php if (array_key_exists('invoice', $add_product_errors)) echo ' <span class="error">' .$add_product_errors['invoice']. '</span>'; ?>
<label for="track"><strong>Upload File</strong></label>
<input type="hidden" name="MAX_FILE_SIZE" value="5120000" />
<input type="file" name="song" id="song" <?php if (array_key_exists('song', $add_product_errors)){ echo " class=\"error\" /> <span class=\"error\">" .$add_product_errors['song']. "</span>"; }else{ echo ' />'; if (isset($_SESSION['song'])){ echo " CURRENTLY '{$_SESSION['song']['file_name']}'"; } } ?>
<input type="submit" name="upload_files" id="upload_files" value="Upload Files" />
</form>
和我的PHP腳本;
if(isset( $_POST['upload'])){ if(is_uploaded_file($_FILES['song']['tmp_name']) && ($_FILES['song']['error'] == UPLOAD_ERR_OK)){ $file = $_FILES['song']; $size = ROUND($file['size']/1024); if($size > 5120000){ $add_product_errors['song'] = 'The File Size is too Big'; }// END FILE SIZE $allowed_mime = array('audio/wav', 'audio/x-wav', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip', 'text/plain'); $allowed_extensions = array('.wav', '.zip', '.rar', '.txt'); $ext = substr($file['name'], -4); if((!in_array($file['type'], $allowed_mime)) || (!in_array($ext, $allowed_extensions)) ){ $add_product_errors['song'] = "We Only accept .wav and .zip files please do not send .mp3 files"; }// END IF WRONG EXT if (!array_key_exists('song', $add_product_errors)){ $dest = "clients/" . $username[0] . "/" . $_POST['invoice'] . "/" . $file['name']; if(move_uploaded_file($file['tmp_name'], $dest)){ // $_SESSION['image']['new_name'] = $new_name; $_SESSION['song']['file_name'] = $file['name']; $add_product['text'] = "Files has successfully been moved
\n"; }else{ trigger_error('the file could not be moved.'); unlink($file['tmp_name']); }// END if file is moved }// END if file can be moved }elseif (!isset($_SESSION['song'])){ switch ($_FILES['song']['error']){ case 1: case 2: $add_product_errors['song'] = "File is too big 5GB Max"; break; case 3: $add_product_errors['song'] = "the file was partially uploaded"; break; case 6: case 7: case 8: $add_product_errors['song'] = "Couldn't upload due to a system error"; break; case 4: default: $add_product_errors['song'] = "No file was uploaded"; break; }//END OF SWITCH } if(empty($add_product_errors)){ echo 'yes'; $body = $username[0] . " has uploaded files in to " . $_POST['invoice'] . " Ready to start downloading and working on"; //mail($site_email, 'file has been loaded',$body,'from:' .$site_email); //$_POST = array(); //$files = array(); unset($file,$_SESSION['song']); } }//END IF $_POST UPLOAD
任何幫助將不勝感激謝謝
嘗試刪除mime類型的檢查,然后先查看它的作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.