How to Upload Mp3 File to Server
#1
Uploading mp3 files to remote server
Posted 05 July 2012 - 09:09 AM
Hello all,
Then I take a website where users volition exist able to upload an mp3 file. The issue I have is that the web server is different than the server that is going to be hosting the information.
This is my script for uploading the script
<?php //********************************************************************************************** echo "Delight wait while we attempt to upload your file...<br><br>"; //********************************************************************************************** $target_path = "uploads/"; $flag = 0; // Condom net, if this gets to ane at any point in the process, we don't upload. $filename = $_FILES['uploadedfile']['name']; $filesize = $_FILES['uploadedfile']['size']; $mimetype = $_FILES['uploadedfile']['type']; $filename = htmlentities($filename); $filesize = htmlentities($filesize); $mimetype = htmlentities($mimetype); $target_path = $target_path . basename( $filename ); if($filename != ""){ repeat "Beginning upload process for file named: ".$filename."<br>"; echo "Filesize: ".$filesize."<br>"; echo "Type: ".$mimetype."<br><br>"; } //First generate a MD5 hash of what the new file name volition be //Force a MP3 extention on the file we are uploading $hashedfilename = md5($filename); $hashedfilename = $hashedfilename.".mp3"; //Check for empty file if($filename == ""){ $fault = "No File Exists!"; $flag = $flag + 1; } //Now we cheque that the file doesn't already exist. $existname = "uploads/".$hashedfilename; if(file_exists($existname)){ if($flag == 0){ $error = "Your file already exists on the server! Please cull another file to upload or rename the file on your computer and try uploading it once more!"; } $flag = $flag + one; } //Whitelisted files - Only allow files with MP3 extention onto server... $whitelist = assortment(".mp3"); foreach ($whitelist as $ending) { if(substr($filename, -(strlen($catastrophe))) != $catastrophe) { $error = "The file type or extention you are trying to upload is not immune! You can only upload MP3 files to the server!"; $flag++; } } //Now we cheque the filesize. If it is as well large or too small and then nosotros pass up it //MP3 files should exist at least 1MB and no more than vi.5 MB if($filesize > 6920600){ //File is as well large if($flag == 0){ $error = "The file yous are trying to upload is besides large! Your file can be upwards to 6.5 MB in size only. Please upload a smaller MP3 file or encode your file with a lower bitrate."; } $flag = $flag + 1; } if($filesize < 1048600){ //File is too small if($flag == 0){ $error = "The file you are trying to upload is too small! Your file has been marked every bit suspicious because our system has determined that information technology is too small to be a valid MP3 file. Valid MP3 files must be bigger than 1 MB and smaller than 6.five MB."; } $flag = $flag + 1; } //Check the mimetype of the file if($mimetype != "audio/x-mp3" and $mimetype != "audio/mpeg"){ if($flag == 0){ $mistake = "The file you are trying to upload does non contain expected data. Are you sure that the file is an MP3?"; } $flag = $flag + i; } //Check that the file really is an MP3 file past reading the showtime few characters of the file $f = @fopen($_FILES['uploadedfile']['tmp_name'],'r'); $s = @fread($f,three); @fclose($f); if($s != "ID3"){ if($flag == 0){ $error = "The file you lot are attempting to upload does not appear to exist a valid MP3 file."; } $flag++; } //All checks are done, really movement the file... if($flag == 0){ if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { //Alter the filename to MD5 hash and Forcefulness a MP3 extention. if(@file_exists("uploads/".$filename)){ //Rename the file to an MD5 version rename("uploads/".$filename, "uploads/".$hashedfilename); echo "The file ". basename( $filename ). " has been uploaded. Your file is <a href='uploads/$hashedfilename'>here</a>."; } else{ echo "There was an error uploading the file, please endeavour again!"; } } else{ repeat "There was an mistake uploading the file, please try once more!"; } } else { echo "File Upload Failed!<br>"; if($error != ""){ echo $fault; } } ?> merely this script is meant for the host server. All the data I found is moving from the local to the remote, I would really rather it go directly to the remote.
Whatever tips on how I tin practise this?
This post has been edited by iamcenz: 05 July 2012 - 09:17 AM
#2
Re: Uploading mp3 files to remote server
Posted 05 July 2012 - 09:46 AM
Are you saying you take something like this?
------------- -------------- ------------------ | | | | | | | Browser |----------->| Webserver |---------->| Hosting Server | | | | | | | ------------- -------------- ------------------
and yous want to go direct to the hosting server from the browser? You tin can if the hosting server's exposed to the Cyberspace and is running a web server itself. You just fix the form's activeness to point to that server instead of the web server. Otherwise, you lot probably desire to replace move_uploaded_file() with a call to a function which uses cURL (or some other filesystem method, like rcp or something) to put the file on the remote server.
#3
Re: Uploading mp3 files to remote server
Posted 05 July 2012 - x:30 PM
JackOfAllTrades, on 05 July 2012 - 11:46 AM, said:
Are you saying y'all have something similar this?
------------- -------------- ------------------ | | | | | | | Browser |----------->| Webserver |---------->| Hosting Server | | | | | | | ------------- -------------- ------------------
and you want to go directly to the hosting server from the browser? You can if the hosting server'southward exposed to the Internet and is running a web server itself. You just gear up the form'southward activity to signal to that server instead of the web server. Otherwise, you probably want to replace move_uploaded_file() with a call to a function which uses whorl (or some other filesystem method, like rcp or something) to put the file on the remote server.
that is pretty much it, i have a shared host from Liquid Web, so I have another server that my friend is being so kind to host in his companies server colo. The site is hosted on Liquid Web, that is where the database and everything is stored. What I'k looking to practice is take a user upload a mp3 file to to the server in the colo from the website hosted on Liquid Web. I am trying to have a directly connection to the 2nd server. There is no manner to accept a vpn or map a virtual drive or anything like that. I perfer not to have the file saved to the hosting server then moved to the data server, I would rather it go straight to the data server.
#iv
Re: Uploading mp3 files to remote server
Posted 07 July 2012 - 01:23 AM
Is there a HTTP server on the hosting-server? If non, and then your sort of out of options. Y'all can't directly the user'southward browser to upload a file to the hosting-server without it having a HTTP server running. You might be able to sort of relay the file through the web-server without actually saving it there, beyond the temporary file, simply I suspect that isn't exactly what you want.
If in that location is a HTTP server running on the hosting-server, then having the user upload the file there is a simple matter of irresolute the form's action aspect. Of grade, you'll probably have to rearrange some things to pass along whatsoever other relevant data to the web-server. I'd suggest yous but take any other file details submitted beginning to the web-server, so redirect to the hosting-server and provide a second form for the file upload who'due south activeness points to the hosting-server. It would have to pass along some sort of a token that the hosting-server can use to query the web-server with in order to verify that the file upload should be immune. Otherwise just anybody could upload files to it.
To put it simply:
- Browser submits file meta-information form to web-server.
- Web-server redirects the browser to the hosting-server, passing forth a authorization token via the query-string.
- Hosting-server sends a request to the web-server, in the background, to verify the authorization token. (To prevent but everyone from uploading files.)
- If web-server returns OK on the token, hosting-server provides a file upload form to the browser.
- Browser sends the upload grade to hosting-server, which processes it and saves the file.
- Hosting-server redirects the browser to a "Success" page on the web-server.
#five
Re: Uploading mp3 files to remote server
Posted 18 July 2012 - 07:49 PM
Atli, on 07 July 2012 - 03:23 AM, said:
Is there a HTTP server on the hosting-server? If non, then your sort of out of options. You can't direct the user's browser to upload a file to the hosting-server without information technology having a HTTP server running. You might be able to sort of relay the file through the spider web-server without really saving it in that location, beyond the temporary file, but I suspect that isn't exactly what you desire.
If in that location is a HTTP server running on the hosting-server, then having the user upload the file in that location is a simple matter of changing the grade's activity aspect. Of course, you'll probably have to rearrange some things to laissez passer along any other relevant data to the web-server. I'd suggest you just take whatsoever other file details submitted offset to the web-server, and then redirect to the hosting-server and provide a second form for the file upload who'south action points to the hosting-server. It would have to laissez passer along some sort of a token that the hosting-server tin can use to query the web-server with in order to verify that the file upload should be allowed. Otherwise just everyone could upload files to it.
To put it simply:
- Browser submits file meta-data form to web-server.
- Web-server redirects the browser to the hosting-server, passing forth a authorisation token via the query-cord.
- Hosting-server sends a request to the spider web-server, in the groundwork, to verify the authorization token. (To forestall just anybody from uploading files.)
- If web-server returns OK on the token, hosting-server provides a file upload form to the browser.
- Browser sends the upload grade to hosting-server, which processes it and saves the file.
- Hosting-server redirects the browser to a "Success" page on the web-server.
would you exist able to testify a little snippet on how this would work?
I need some data including the file name(which my script renames) to go into a database on the webserver.
lockettawalinis1955.blogspot.com
Source: https://www.dreamincode.net/forums/topic/284847-uploading-mp3-files-to-remote-server/
0 Response to "How to Upload Mp3 File to Server"
Post a Comment