File upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steveatk
Forum Newbie
Posts: 6
Joined: Sat Dec 27, 2003 9:52 am

File upload

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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?
steveatk
Forum Newbie
Posts: 6
Joined: Sat Dec 27, 2003 9:52 am

Post 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 :)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Very welcome.

But others might want to comment on this. I never personally needed 'not to have them uploaded', but others might.
steveatk
Forum Newbie
Posts: 6
Joined: Sat Dec 27, 2003 9:52 am

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply