tags:

views:

61

answers:

2

When i use an html form to post a file, how do i address that file's contents in php?

will this work?

$data = $_POST['file'];
$pre = explode(";;;", $data);

the file is a text file btw

UPDATE
the csv is field enclosed with ::: and lines terminated by ;;;. How can i load this into a variable without breaking the php script, which is what is happening now

+1  A: 

No, it will not work. You'll need to save the file locally, first, and open the file with something like file_get_contents(). Please read the PHP Tutorial on File Uploads

Martin Hohenberg
+2  A: 

umm you can do

$data = file_get_contents($_FILES['file']['tmp_name']);
$pre = explode(";;;", $data);

something like that should work

Sabeen Malik
you meant "file_get_contents()", right?
Martin Hohenberg
sorry .. yes just fixed it :)
Sabeen Malik
its saying the file is empty.
Patrick
ah i am getting lazy .. sorry about that :) ... it should be $_FILES not $_FILE .. try the code now
Sabeen Malik
this has to be worst ever line of code i have written .. 3 mistakes in one line .. wow!
Sabeen Malik