Tutorial :Partial uploads, upload only header


Is there a way in PHP use a HTML form to upload only the header of the file. The length of the header is defined within the first few bytes of the file, I want only that part nothing else. After I have received the last byte of the header, I don't want any more of the file. Is there a graceful way to do this in PHP or am I going to have to do some socket programming?


In the PHP side, you cannot abort an upload (HTTP connection) gracefully. The client would face a "connection reset by peer" error (or whatever friendlier flavored message the webbrowser made out of the error). Best what you can do is to ignore the read bytes, but that's not (clearly?) easy in PHP since it's a pretty high level language.

In the HTML side, there's absolutely no way to upload only the "header" of a file. It's the complete file or nothing. There are countless different file formats and HTML has no notion of any of them, let alone know how to distinguish the "header" part of the file in question.

Your best bet is to write a little application which get served by the webpage and downloaded into client's machine and runs locally over there. This application should have a file chooser/picker/opener and then programmatically determine the "header" and send it to the server. You could do that in flavor of a Java Applet or MS Silverlight or probably Adobe Flash.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »