首页 文章

PHP上传表单问题

提问于
浏览
0

我使用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

任何帮助都会非常感谢谢谢

1 回答

  • 0

    尝试删除mime类型的检查并查看它首先给出的内容

相关问题