简体   繁体   中英

cant upload audio file php

hi i cant upload audio file with this code, its the same code i used for image upload but its not working for video and audio. And yes i changed the values in php.ini but yet it is still the same

<?php

            if(isset($_POST['submit'])){
                $uploaderror='';
                            $target_dir = "../user/henboc/";
                            $target_file = $target_dir . basename($_FILES["userfile"]["name"]);
                            //$file_size = $_FILES['userfile']['size'];
                            $file_name = $_FILES['userfile']['name'];
                            $temp_dir = $_FILES["userfile"]["tmp_name"];
                            $ext_str = "jpg,jpeg,png,mp3,tiff,bmp,doc,docx,txt,pdf,ppt,pptx";
                            $ext = substr($file_name, strrpos($file_name, '.') + 1);
                            $allowed_extensions=explode(',',$ext_str);


                            if (move_uploaded_file($temp_dir, $target_file)){

                             echo '<div class="alert alert-danger">
                                                        <strong>Error!</strong> Name already exist
                                                   </div>';
                            }

                        //
            }


            ?>

and my html

<form class="form-horizontal form-label-left" method="post" action="" enctype="multipart/form-data" role="form">


                 <br>

             <label for="fullname">Upload Music</label>
                  <input type="file" class="form-control" name="userfile" id="userfile" />

                 <br>
                  <div class="ln_solid"></div>
                  <div class="form-group">
                    <div class="col-md-6 col-md-offset-3">
                      <button type="" class="btn btn-primary">Cancel</button>
                     <button type="submit" class="btn btn-success" name="submit">Submit</button>
                    </div>
                  </div>

                </form>

MY php.ini

post_max_size = 24M
upload_max_filesize = 20M

Okay your PHP script seems to be working fine for me. Here are the steps you should check:

  1. If your PHP code is not in the same file as the HTML, you should adjust the action="" attribute of your form tag.
  2. Double check your target directory. Is the folder existing?
  3. Did you restart the server after changing the php.ini? Does the upload work with very small files?

If your problem still persists you may want to use this snippet for getting specific information about the error cause.

post_max_size = 24M
upload_max_filesize = 20M

This is not all that needs tuning. As file uploads goes via POST request, you must have also ensure that all timeouts are not reached before upload is completed, so ie max_execution_time and max_input_time . I'd also check error log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM