简体   繁体   English

无法上传音频文件的PHP

[英]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.ini中的值,但仍然相同

<?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 和我的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 我的php.ini

post_max_size = 24M
upload_max_filesize = 20M

Okay your PHP script seems to be working fine for me. 好的,您的PHP脚本对我来说似乎很好。 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. 如果您的PHP代码与HTML不在同一个文件中,则应调整表单标签的action=""属性。
  2. Double check your target directory. 仔细检查您的目标目录。 Is the folder existing? 该文件夹是否存在?
  3. Did you restart the server after changing the php.ini? 更改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 . 由于文件上传是通过POST请求进行的,因此您还必须确保在上传完成之前未达到所有超时,例如max_execution_timemax_input_time I'd also check error log. 我还要检查错误日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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