The online racing simulator
PHP question - partially uploading files?
Hi, I'm doing some work on a new league project and I've come to uploading results.

My initial idea is to get the results from the mpr header. I have already done that, using an hex editor to extract just the header. But now I'm wondering if there is a way to upload a file partially using PHP, or opening it directly from my local machine. This way I don't have to upload a full mpr file which can be several MBs big, or edit it with any software to extract the header.

So, the main idea is to be able to parse the mpr file header without having to upload it completely. Any help?
As far as I know, no you can't do it with PHP's default, built in mechanisms as far as POSTing the results. If the client uses PUT, then you have instant access to the raw data that is being uploaded, while it is uploading but that's only for a few browsers. The only cross playform solution that I can think of is uploading to a socket on your webserver, with a PHP demon sitting at the other end waiting for files to uploaded to it. This will work across browser, and you'll have instant access to the data stream, so that you can parse as it comes in. The only question then would be, how do you tell the client to stop uploading gracefully?

It was just confirmed to me that PHP can't handle this kind of situation using built in mechanisms. Your going to have to make a demon, and it's not going to be pretty. Unless you dress it up with some AJAX ... but you know we can't trust AJAX to always work ... It's a lose, lose situation at this point. Let them suffer with the cost of a full upload, or let them deal with a hacky workaround that will not work for all cases (like when JavaScript is turned off, and will produce the Connection Reset by Server error message when you upload a file.)
An option would be to create some sort of browser applet (Flash, Silverlight, Java etc..) and use that to upload the data to your site. This way you could vastly reduce the amount of data that gets transferred, also you offload the actual parsing of the replay to the users computer.
Quote from MaKaKaZo :Hi, I'm doing some work on a new league project and I've come to uploading results.

My initial idea is to get the results from the mpr header. I have already done that, using an hex editor to extract just the header. But now I'm wondering if there is a way to upload a file partially using PHP, or opening it directly from my local machine. This way I don't have to upload a full mpr file which can be several MBs big, or edit it with any software to extract the header.

So, the main idea is to be able to parse the mpr file header without having to upload it completely. Any help?

The only available upload possibility directly in php is using $_FILES (html form post).

You can stream files stored on a server - but not from the client. Getting access to a client's file system would be a security risk - and therefore is not possible in PHP.

Alternatively - you could look into Java applets - or perhaps using an AJAX uploader - but - this needs to be given permission to do this.

Realistically - an AJAX based uploader to upload a complete file (a large one) would be safest way to do things - opening the mpr file afterwards.

But - a "COMPILED" php script ( google bamcompile ) -> as an exe will have the access to the file system its running from (eg : the client ) you will need to do this without uploading - some research and I think you can come up with some good ideas.


EG:

--> client downloads compiled PHP script ( compiled to unix or win32 ) ( this can have access to GTK btw )

--> MPR loaded into executable script on client side...
--> Header extracted by client PHP script
--> passed to web url via HTTP vars (Post/Get please) as binary safe string to a web site
--> website processes the header the compiled exe sent to it

It does mean having the client to download a small file first - BUT means that you don't have to use multiple programming languages...
Thanks guys for all your replys. You are proposing solutions that, honestly, are not worth the effort for this matter. I mean, I'd rather use some basic hex editor to cut the mpr file header manually and upload it than try any of the things you propose.

After talking to my project-mate I'm going to do some research about a new approach, that would be to upload the results automatically into the MySql DB via insim. I already have some insim applications handling data from the DB, I just have to take a look into the available packets to see if it is reasonable to try and do it that way, which would be in my opinion the coolest solution to the problem of uploading results, to have them upload themselves automatically through the insim application that will be used to control the races.
Quote from MaKaKaZo :After talking to my project-mate I'm going to do some research about a new approach, that would be to upload the results automatically into the MySql DB via insim. I already have some insim applications handling data from the DB, I just have to take a look into the available packets to see if it is reasonable to try and do it that way, which would be in my opinion the coolest solution to the problem of uploading results, to have them upload themselves automatically through the insim application that will be used to control the races.

The packet your looking for is the IS_RES, just be-careful about using this packet during qualifying as each new lap will produce a new IS_RES packet. And two thumbs up on that choice, InSim would be a billion times better way to handle this.

FGED GREDG RDFGDR GSFDG