Page 1 of 1

File upload

Posted: Sat Dec 27, 2003 9:52 am
by steveatk
I'm expanding on my log file parser for members of a gaming community I belong to and I would like to add a function where a user can browse their own pc for a log file and then the site will take that as it's input for parsing.

I don't want the file uploaded to the server, (obviously it will need to be uploaded, but I dont want a file created on the server hopefully) I just want the file to be read into some variable or storage space which the parser will then use to display useful information to the uploader.

If it's not possible to do this then I will upload the file temporarily and delete it again but I would rather not.

The main thing stopping me here is I need the user to be able to browse for a file for upload which I have no experience with doing.

Any help would be appreciated.

Posted: Sat Dec 27, 2003 11:11 am
by JAM
This is a good place to start playing with. $_FILES will contain the information you might find interesting.
( http://se.php.net/manual/en/features.file-upload.php for more info. )

Code: Select all

<pre>
<?php
    print_r($_FILES);
?>
<form enctype="multipart/form-data" method="POST">
<input type="file" name="userfile">
<input type="hidden" name="MAX_FILE_SIZE" value="24000">
<input type="submit" value=" Send File ">
</form>
About not actually uploading the file... Don't think that is possible. A javascript guru might solve it in some odd way, but...

Is there a certain reson of why you dont want the file uploaded/copied/read/deleted?

Posted: Sat Dec 27, 2003 11:43 am
by steveatk
no reason really for not wanting the file uploaded, it just seems neater to me not to as it will only be used briefly and never stored beyond the session, but if it does need to be uploaded then that's fine.

Thanks for the snippet, I'm fairly sure I've come across it before as it looks familiar but I've never used it.

This is exactly what I needed actually, thanks :)

Posted: Sat Dec 27, 2003 11:49 am
by JAM
Very welcome.

But others might want to comment on this. I never personally needed 'not to have them uploaded', but others might.

Posted: Sat Dec 27, 2003 11:59 am
by steveatk
Just to clarify for further discussion if anyone wanted to continue this thread...

By 'not uploading' what is meant is the ability to upload the data directly into memory and store it within a variable without having to create a temp file on the server first and then read from that file to populate any variables in your program.

Posted: Sat Dec 27, 2003 12:07 pm
by JAM
Just a thought you can play around with...

There are javascripts that can read filecontents. That 'content', whatever it might be, can be posted. The idea was mainly to read the file, populating a <textarea> with it's content, and send that to $_POST. That was you might find a way to pass the uploading part of the script.

Just thoughts.