提问者:小点点

PHP上载表单问题


我有问题上传表单使用php,我曾经创建过这样的页面,但由于某种原因,这似乎是渲染,我希望我只是错过了一些如此简单的东西。Im试图创建和上传表单,以上传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

如果有任何帮助,我将不胜感激谢谢


共1个答案

匿名用户

尝试删除mime类型的检查,然后先看看它给出了什么