For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2008 > file upload prob. php cant find temp dir









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author file upload prob. php cant find temp dir
mike

2008-03-08, 7:01 pm

Hi

I am new and trying to learn php. I am trying to use some of the scripts
in the php manual (http://www.php.net/manual/en/) to upload a file. I
can not seem to get the file to upload. Actually I am "uploading" to the
same Windows XP computer, trying to move the file from one directory to
another. It appears that the file is suppose to be passed to a temporary
file in a temporary directory. I think this is where I am having
trouble. The form script seems to get the file correctly. It calls and
posts to the file processing script correctly. But the file
processing script fails. I get error 6 which is "Missing a temporary
folder." ( I am using IIS server with an ISAPI, see below for complete
scripts and outputs)

If I do a phpinfo() call I see that upload_tmp_dir is not set
if I do $a=ini_get('upload_tmp_dir'); and echo $a I get NULL.

The manual says that 'upload_tmp_dir' is set in php.ini. I found
php.ini in the Program Files/php/ directory. I find the variable set
in 2 places in that file:

******
..
..
..
; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default
;if not
; specified).
;upload_tmp_dir =
..
..
..
; Default timeout for socket based streams (seconds)
default_socket_timeout = 60
upload_tmp_dir="C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\upload"
session.save_path="C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\session"
..
..
..
*********
The directory set in the 2nd instance:

upload_tmp_dir="C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\upload"

exists on my pc, however, phpinfo() says 'upload_tmp_dir' is not set.

If I uncomment the 1st instance and set it:

upload_tmp_dir ="C:\tempphp" (a directory which I have created)

phpinfo() reports 'upload_tmp_dir' is not set.

I have tried puting the php.ini file in my wwwroot directory and in
the working directory containing the scripts (I think this is where it
should be) and still phpinfo() reports 'upload_tmp_dir' is not set.

I have also tried ini_set('upload_tmp_dir', 'C:\tempphp');
that also does not work.

The phpinfo() reports that the default path to the file is C:\windows.
so I have placed the php.ini file in that directory. phpinfo still
reports 'upload_tmp_dir' not set.

****************************************
*****
Q1: How do I set the temporary upload file 'upload_tmp_dir' in windows
XP. If there is a default one why am I getting error 6, missing temp
directory.

Q2: Once I have set 'upload_tmp_dir' how do I know the temproary file
name 'tmp_name' that php uses to hold that file before it gets moved using:

move_uploaded_file($_FILES['userfile']['
tmp_name'], $uploadfile)

Thank You
Mike



****************************************
****
I use the following to generate a form to get the file name:
*****

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data"
action="http://localhost/php/upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
<h1> hello world</h1>
</body>
</html>

****************************************
**
Then I use the following php script (http://localhost/php/upload.php) to
do the moving:
******

<html>
<body>
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used
instead
// of $_FILES.

$uploaddir = './upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile'][
'tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload problem\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>
</body>
</html>
***********************************

I get the following output:

*******

Possible file upload problem
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => usage_rights.txt
[type] =>
[tmp_name] =>
[error] => 6
[size] => 0
)

)
Olaf Schinkel

2008-03-09, 8:40 am

mike schrieb:
> Hi
>
> I am new and trying to learn php. I am trying to use some of the scripts
> in the php manual (http://www.php.net/manual/en/) to upload a file. I
> can not seem to get the file to upload. Actually I am "uploading" to the
> same Windows XP computer, trying to move the file from one directory to
> another. It appears that the file is suppose to be passed to a temporary
> file in a temporary directory. I think this is where I am having
> trouble. The form script seems to get the file correctly. It calls and
> posts to the file processing script correctly. But the file
> processing script fails. I get error 6 which is "Missing a temporary
> folder." ( I am using IIS server with an ISAPI, see below for complete
> scripts and outputs)
>
> If I do a phpinfo() call I see that upload_tmp_dir is not set
> if I do $a=ini_get('upload_tmp_dir'); and echo $a I get NULL.
>
> The manual says that 'upload_tmp_dir' is set in php.ini. I found
> php.ini in the Program Files/php/ directory. I find the variable set
> in 2 places in that file:
>
> ******
> .
> .
> .
> ; Whether to allow HTTP file uploads.
> file_uploads = On
>
> ; Temporary directory for HTTP uploaded files (will use system default
> ;if not
> ; specified).
> ;upload_tmp_dir =

THIS IS A COMMENT

> .
> upload_tmp_dir="C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\upload"

You should know, that the *WEBSERVER* Account must have Access to that
directory, not the logged User!?

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com