This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to stream a WAV file?
I am developing a website where users can compose their own music, and the site will generate a .wav file for their creation. This is working correctly (inasmuch as I can play it on the page). However, I would like to save this file to the server to be listened to/downloaded at a later time, and the saved version of the file can no longer be opened and played by the HTML audio tag.
What, if anything, must I put into the file besides the file besides the raw data? Instead of setting the src attribute of the audio tag to the location of the file, will I actually need to open it and generate a URI?
At the moment, what I'm doing to play the wav file looks like this:
wav = [headerChunk, fmtChunk, dataChunk].join('');
var URI = "data:audio/wav;base64," + escape(btoa(wav));
document.getElementById("player").setAttribute("src", URI);
To save this, I'm just writing 'wav' directly into a file; I then try to play it back by setting the audio tag's src to be the location of that file on the server.
I hate to be the bearer of bad news, in an ideal world you will need to post the file with JQuery, but I don't think you have the file as you think you do, (you may do, but it's not really likely, there are too many security walls around things) it's much more likely that you a) have a Java Object with the file in it, or b) (much more likely) a flash object with the music in it.
In which case it's this "Box-of-tricks" that needs to be told to post it: i.e. if you are in browser client with a music file as a physical file then you probably downloaded it, if you edited/created it in the browser somehow you probably have a flash object with it in memory within -- in which case getting flash to post it is your only way
Related
This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 7 years ago.
I would like to implement a PHP web page that, given a certain URL, is going to sniff some images from that page.
Do to so, I need :
1) to access the html source-code of that page and find out the URLs of the images I want.
2) to download these images on my FTP
I don't know how to do these two tasks, I guess I will have to use third party libraries, but this is the first time I need to do so and I am not sure.
Any advices ?
Thank you.
This is actually quite a simple task in PHP:
Use file_get_contents() to fetch the HTML from any random page (cURL would work too).
Using DOMDocument, find all img tags inside the page (see getElementsByTagName() method)
Extract the src attribute from each node.
Download the images somewhere with cURL.
Use the FTP functions to upload them to your server (or use a library like this one).
Did you mean grab html page's images and download them and then upload these images to your own FTP server?
If I catch on you correctly, this task will be completed by plain PHP code, no need of third party libraries.
Use preg_match_all to match all images out
Download them(use curl or file_get_content)
upload them to your FTP server, you can simply use curl again, put that image you downloaded above(you don't need save image in your PHP located machine, it is a File Stream in memory) in POST request body then send the request. Or upload image using FTP related functions(find that function in PHP net Document)
You need do step 2 and 3 in a loop basing on data generated from step 1.
Tell me if you need help about them.
This is going to sound like an odd request.
I have a PHP script pulling a mp3 stream from SoundCloud and repeating the stream with the correct headers to allow WinAmp to play the file. But it only shows the local url I have the script running from. Before anyone asks, I am injecting ID3v1 into the file before echoing it.
Is there any way to provide WinAmp with the meta data from php?
Just to clarify, you are effectively proxying an MP3 file from SoundCloud, and you want to embed metadata into it?
Winamp will pick up ID3 tags in an HTTP-served MP3 file. However, if you are using ID3v1, those tags don't exist until the very end of the file. If you want the file to be identified without having to download the whole file, you must use ID3v2 which are typically located at the beginning of the file. (I actually recommend using both ID3v1 and ID3v2 for broader player compatibility, but almost everything supports ID3v2, so it is your choice.)
Now, there is another method but if you use this method the metadata won't be saved in the file when downloaded. You can use SHOUTcast-style metadata. Basically, Winamp and other clients (like VLC) send a request header, Icy-MetaData: 1. This tells the server that it supports SHOUTcast-style metadata. In your server response, you would insert metadata every 8KB or so. Basically, you want the reverse of what I have detailed here: https://stackoverflow.com/a/4914538/362536
In the end, simply adding ID3v2 tags will solve your problem in the best way, but I wanted to mention the alternative option in case you needed it for something else.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to check file types of uploaded files in PHP?
Creating a text file and rename it to anything.jpg and try uploading it on facebook, facebook detects that the file is not an image and says Please select an image file or something like that. How do they do it?
I tested it out on my localhost by creating a dummy html form along with a <input type="file"... element and uploaded an image file created by renaming a text file to something.jpg and the file type in $_FILES['control_name']['type'] showed image/jpeg... How do I block users from uploading such 'fake' images. I think restriction using $_FILES['control_name']['type'] is not a solution, right?
When you process image on server, use image manipulation library (getimagesize for example) to detect it's width and height. When this fails, reject the image. You will probably do it anyway to generate thumbnail, so it is like one extra if.
There are many ways of checking the actual files. How Facebook does it, only the ones who created it know i think :).
Most likely they will look at the first bytes in the file. All files have certain bytes describing what they truely are. For this however you need loads of time/money creating a database or such against which you can validate the uploads.
More common solutions are;
FORM attribute
In a lot of browsers, of course excluding Internet Explorer, you can set an accept attribute which checks on extensions client side. More info here: File input 'accept' attribute - is it useful?
Extension
This is not realy secure, for a script can be saved with an image extension
Read file MIME TYPE
This is a solution like you stated in your question. This however is also easy to bypass and relies on the up-to-date status of your server.
Processing the image
The most reliable (for most developer skills and available time) would be to process the image as a test.
Put it in a library like GD or Imagic. They will raise errors when an image is not realy an image. This however will require you to keep that software up to date.
In short, there is not a 100% guarantee to catch this without spending tons of hours. Even then you only get 99,9%. You should weigh your available time against the above options and choose which best suits you. As best practice i recommend a combination of all 3.
This topic is also discussed in Security: How to validate image file uploads?
Headers in your file won't be the same.
Currently working on an offshoot of the idea more adequately addressed here.
Creating a Secure File Hosting Server for PDFs
I'm developing a secure PDF hosting website where certain users can download certain PDF's that I have stored outside of the webroot to prevent people from accessing documents they shouldn't access.
I've got the download working using the first solution, but I want to implement a 'view/preview' feature too. I still don't get content headers as well as I should but I believe what is causing the bulk of my issues is I can't put a 'src' attribute on the embed/object/iframe/whatever. And that's kind of the point of the system.
My question is, is there any way to feed a file (as opposed to a url) to an embed/object? I would like to keep my current system and I'm going for simplicity at the moment so the easier the better.
I saw Recommended way to embed PDF in HTML? and will probably check out pdf.js if I'm trying something that isn't doable.
I have not yet had the chance to play with pdf.js, but it either that or a flash player of some sort.
Or you rely on the browser to display it has a webpage and you can iframe it, but that's so lame... it would work only for a fraction of you users.
PDF2SWF - convert PDF to SWF ( 1 page = 1 SWF).
Use other SWF (reader) to load SWF pages via XML or something else.
Use $_SESSION to store ID of PDF document which should be served through e.g. /preview (same link for previewing all documents)
Don't serve original PDF, put a watermark, or make them low-res.
Otherwise, your PDF will never be "secure".
http://www.swftools.org/
So would like to do: get an flv file from a protected directory and feed it to a swf embedded player as a parameter using PHP.
Is this possible?
Sending the contents of the file to the embedded player does not seem to work.
Well, since the player requires that the client fetches both the player and the FLV from the server, I suspect that this would require a temporary location from which the FLV is made accessible to the user via a URL. The most obvious solution is to create an expiring URL that times out in a reasonable amount of time, preventing users from linking directly to the FLV. I'm not sure if there's a way to keep it protected beyond this without embedding the address to the file in the flash itself dynamically - basically, you can't use a general purpose player that takes a URL for the FLV as a parameter if additional protection is required.
Edit: Here is a potential solution using the JW player: Code URL in V4 for protection against leechers
And here is another possible solution along the lines of my original comment: Flashcomguru.com: 'Streaming' flv video via PHP, take two
The Flashcomguru link look promising, not sure I understand this stuff however.
I'm not a Flash guy but I know someone that may be able to help.
I'm also not sure how to create a 'create an expiring URL"
Not sure what you mean with "feed it to a swf embedded player as a parameter using PHP", but looks like what you want to do is this:
Store your flv file somewhere outside the DocumentRoot in your server.
Create a PHP script that based on some parameter, reads the flv file and serves it. I'm assuming that you are planning to have some authentication in this php script to prevent anyone from just calling your PHP script and getting the flv as if it was in the DocumentRoot
Create an swf clip that will call the PHP script to retrieve the flv to the client.
If that is what you want, the part of the script in 2 that reads and serves the flv should be pretty straight forward using the standard file accessing functions from the PHP API and setting the appropriate content-type header before echoing it out.