Best way to get the contents of a local file in a server variable
Best way to get the contents of a local file in a server variable
am 29.10.2007 20:07:29 von Fons
My script acts on a file (approx. 100k) offered by the user. Actually, it
acts on a variable that should have the contents of that file in it. I
could try to let users upload that file and then read that file into a
variable, but before I figure out how to do that: is this unnecessary
overhead? Is it possible to do it without creating a file on the server
filesystem and do it completely within the PHP framework? What method
would you recommend?
Re: Best way to get the contents of a local file in a server variable
am 29.10.2007 20:26:48 von Good Man
Fons wrote in
news:47262f71$0$29261$ba620e4c@news.skynet.be:
> My script acts on a file (approx. 100k) offered by the user. Actually,
> it acts on a variable that should have the contents of that file in
> it. I could try to let users upload that file and then read that file
> into a variable, but before I figure out how to do that: is this
> unnecessary overhead? Is it possible to do it without creating a file
> on the server filesystem and do it completely within the PHP
> framework? What method would you recommend?
>
what are you trying to do?
Re: Best way to get the contents of a local file in a server variable
am 29.10.2007 20:30:19 von luiheidsgoeroe
On Mon, 29 Oct 2007 20:07:29 +0100, Fons wrote:
> My script acts on a file (approx. 100k) offered by the user. Actually,=
it
> acts on a variable that should have the contents of that file in it. I=
> could try to let users upload that file and then read that file into a=
> variable, but before I figure out how to do that: is this unnecessary
> overhead? Is it possible to do it without creating a file on the serve=
r
> filesystem and do it completely within the PHP framework? What method
> would you recommend?
Just let it do a normal fileupload to a/the tmp directory and read it in=
to =
a variable. Anything else will be a waste of time. The code is pretty =
simple:
if(isset($_FILES['your_html_fileinput_name'])){
if($_FILES['your_html_fileinput_name']['error']!=3DUPLOAD_ER R_OK){
echo 'upload error #'.$_FILES['your_html_fileinput_name']['error'];
} else {
$filecontents =3D =
file_get_contents($_FILES['your_html_fileinput_name']['tmp_n ame']);
}
} else {
echo 'no upload took place';
}
-- =
Rik Wasmus
Re: Best way to get the contents of a local file in a server variable
am 30.10.2007 13:59:50 von colin.mckinnon
On 29 Oct, 19:07, Fons wrote:
> My script acts on a file (approx. 100k) offered by the user. Actually, it
> acts on a variable that should have the contents of that file in it. I
> could try to let users upload that file and then read that file into a
> variable, but before I figure out how to do that: is this unnecessary
> overhead? Is it possible to do it without creating a file on the server
> filesystem and do it completely within the PHP framework? What method
> would you recommend?
Explaining the problem better would be a good start.
You can't get a file from the client to the server without uploading
up (unless you use signed javascripts - try a different newsgroup for
more info). 100k is getting a bit large to keep in a PHP variable,
though it will work.
C.