View Single Post

  #14 (permalink)  
Old 03-09-2008
Jeff North
 
Posts: n/a
Default Re: PHP-file upload problem and upload_tmp_dir

On Sat, 08 Mar 2008 11:11:16 -0800, in comp.lang.php mike
<spammesillt@junkmail.com>
<pxBAj.61849$Pv2.56757@newssvr23.news.prodigy.ne t> wrote:

>| 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." (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"


Use either forward slash / or double backslashes \\

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

The single backslash tells most programs/scripts that the next
character is 'special'. When you echo upload_tmp_dir you will see
C:OCUME~1IA-KI~1OCALS~1emphppload

>| .
>| .
>| .
>| *********
>| 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.
>|
>| *********************************************
>| Q1: How do I set the temporary upload file 'upload_tmp_dir' in windows XP.
>|
>| 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
>| )
>|
>| )

-- -------------------------------------------------------------
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
-- -------------------------------------------------------------
Reply With Quote