Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

Im having problems with my uploading form using php I have created pages like this in the past but for some reason this one seems to be playing up I'm hoping i have just missed something so simple. Im trying to create and upload form to upload Wav, rar, zip and txt files and returning error on everything else.

If i try and upload a file which is not related to these it shows an error but if i try to upload a wav or a zip file it doesn't work i don't get any kind of error report but if i was to upload a .txt file it seems to work fine.

my html code is;

           <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>

and my php script;


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

any help would be so much appreciated thank you

share|improve this question
    
Mountain of code, here: Add error reporting to the top of your file(s) error_reporting(E_ALL); ini_set('display_errors', 1); see if it yields anything. – Fred -ii- Nov 5 '14 at 20:40
    
Hi I've just added that to my code and no nothing still empty it seems to work but not upload the files from what I've tried to narrow the error down the if(move_uploaded_file($file['tmp_name'], $dest)){ } is returning true i just placed an echo to see if it would show – ollie8114 Nov 5 '14 at 20:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.