Page 1 of 1

Displaying pictures that are sourced from tmp files

Posted: Wed Mar 24, 2004 3:05 pm
by mjseaden
Dear All

I'm trying to preview pictures uploaded via the FILE input object method. With this method, PHP copies any selected files to a temp directory on the host machine. If you want to upload them, you then use the move_upload function.

I've tried uploading pictures using this method, then reading in the $_FILES['picName']['tmp_name'] to find the pathname of the temporary file (i.e. before using move_upload).

However, IE doesn't seem to like it, and whilst I put in

echo '<IMG SRC="'.$_FILES['picName']['tmp_name']'">'

IE seems to think it is a broken link, showing the characteristic 'X' symbol where the pictures are meant to load.

I've checked that $_FILES['picName']['tmp_name'] is correctly posted, and it is. However this still happens.

Could it be that IE doesn't like any files not ending in 'jpg' or 'gif'? The files are always initially copied to a temporary directory using the affix '.tmp'? Or is it some other problem?

Many thanks

Mark

Posted: Wed Mar 24, 2004 3:09 pm
by markl999
You'll want to move it first, as http://php.net/manual/en/features.file-upload.php states,
"The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed."

Posted: Wed Mar 24, 2004 3:16 pm
by mjseaden
Hi Mark

The page I am referring to is directly after the upload INPUT page. The user selects which files to upload, hits the 'upload' submit button, and are then forwarded to the preview page, in which I am immediately attempting to access the pictures as in their temp form.

Does this still apply?

Posted: Wed Mar 24, 2004 3:22 pm
by markl999
Then you don't need to move it, but ... the img src will be something like /tmp/foo.tmp and this is relative to the document_root, ie it will be looking for /path/to/www/tmp/foo.tmp
Best bet is just to move it, unless there's some reason not to?

Posted: Wed Mar 24, 2004 3:23 pm
by mjseaden
Nope there isn't. Guess that one's sorted out - I'll see how it goes.

thanks

Posted: Wed Mar 24, 2004 3:35 pm
by mjseaden
Mark, in what form do I state the destination path on my site's server?

On the root directory of my server is the usual htdocs, logfiles, and private, but I have also created a directory called 'tmp' as well to upload pictures to.

How do I state this pathname for move_uploaded_files?

Also, another problem I seem to be having is that whilst I set the directory's attributes so that it is publicily writable, it seems to automatically put itself back to publicly unwritable without me requesting that it do so. Is this normal?

Many thanks

Mark

Posted: Wed Mar 24, 2004 3:57 pm
by mjseaden
/bump

Posted: Wed Mar 24, 2004 4:04 pm
by mjseaden
I'm using

Code: Select all

move_uploaded_file($_FILES['photo1_upload']['tmp_name'], "/tmp/");
But I'm getting the error message
Warning: move_uploaded_file(): Unable to move 'C:\WINDOWS\TEMP\php2B79.tmp' to '/tmp/' in \\nas09ent\domains\s\XXXX\user\htdocs\run2.php on line 2270

Warning: move_uploaded_file(/tmp/): failed to open stream: Invalid argument in \\nas09ent\domains\s\XXXXX\user\htdocs\run2.php on line 2271
I think it's likely to do with the way I'm expressing the pathname for the 'tmp' directory on the root directory of my site's server (the same directory level as htdocs/private/logfiles) - that's why I'm asking about the nature of the pathname.

Can anyone help?

Thanks and sorry for all the newbie questions.

Mark

Posted: Wed Mar 24, 2004 4:29 pm
by markl999
Try,
move_uploaded_file($_FILES['photo1_upload']['tmp_name'], $_SERVER['DOCUMENT_ROOT'].'/tmp/'.$_FILES['photo1_upload']['name']);

This should move it to the /tmp directory inside your document root.

Posted: Wed Mar 24, 2004 4:37 pm
by mjseaden
Mark - I'm now getting this:
Warning: move_uploaded_file(/tmp/): failed to open stream: Invalid argument in \\nas09ent\domains\s\XXXX\user\htdocs\run2.php on line 2270

Warning: move_uploaded_file(): Unable to move 'C:\WINDOWS\TEMP\php2B8D.tmp' to '\\\\nas09ent\\domains\\s\\XXXX\\user\\htdocs\\run2.php/tmp/big.jpg' in \\nas09ent\domains\s\XXXX\user\htdocs\run2.php on line 2270

Posted: Wed Mar 24, 2004 4:48 pm
by markl999
Ah...windows...is this IIS by any chance .. or apache?
It's saying your document root is \\\\nas09ent\\domains\\s\\XXXX\\user\\htdocs\\run2.php which is obviously wrong, as that's a file, not a directory.

Posted: Wed Mar 24, 2004 4:54 pm
by mjseaden
Yes it is IIS.

So I take it the pathname I should state should be -

\\\\nas09ent\\domains\\s\\XXXX\\user\\tmp\\<original filename>

?

Because apparently this doesn't work. Although it doesn't produce an error message, when I check the tmp directory for the file the directory is empty.

Also, I notice that even though I change the attributes to allow public read/write of this directory, they seem to change back to disallowing public access on their own at some point without my interference.

Any ideas?

Posted: Wed Mar 24, 2004 4:59 pm
by markl999
Well i tend to go all fuzzy when it comes to IIS, but by the look of it you'll need to use basename($_SERVER['DOCUMENT_ROOT']) instead of just $_SERVER['DOCUMENT_ROOT'] ... but as IIS sets some SERVER vars and not others, and sets some differently to other web servers then i'm just guessing.