简体   繁体   中英

upload mp3 file to server using php

i am trying to upload a mp3 file to server using php code as shown.

$audio=basename($_FILES['file']['name']);
$audio=str_replace(' ','|',$audio);
$tmppath1="audios/".$audio;
move_uploaded_file($_FILES['file']['tmp_name'],$tmppath1);
$query="INSERT INTO `appinstaller`.`tbl_audio` (`audioname`) VALUES ('$audio')";
$res=mysql_query($query);

in this file uploaded successfully but uploading to server taking more time.

is there any method to upload MP3 files faster?

Probably not - what you show doesn't show any obvious bottlenecks. It's likely just the client connection that takes so long.

What you need to fix though is the SQL injection in $audio . See http://php.net/manual/en/security.database.sql-injection.php

The larger the file the longer it takes. You could use a script like uploadify to give you a upload percentage so it dose not look like the browser is hanging, tho there are some security considerations when uploading files, with your script someone could upload anything even PHP, also dont give direct access to the file or allow files to be parsed by php..

You should also use prepared query's as the mysql_* functions are in the deprecation process. http://news.php.net/php.internals/53799

Typically slow upload speeds are due to limited TCP windows (the maximum number of packets that can be in transit between two network locations at any given time). This value is typically determined by the low-level OS drivers and out of your control.

Faster upload speeds may be achieved by parallel data transfers; a file is split up in a couple of pieces and those are transferred in parallel. You will need to determine whether uploading two sets of data simultaneously will actually reduce the transfer time.

Modern browsers expose a JavaScript interface to access local files as a binary stream; some will allow you to (efficiently) read slices of the file into memory and transfer those via AJAX. This is also referred to as chunking.

On the server side, you will need to make changes to support chunking as well. The use of sessions during a parallel upload will cause locking; this may or may not be a problem, depending on your requirements.

Hope this gives you some idea on what you could to look into to "make your upload go faster" :)

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