This is a discussion on PHP-file upload problem and upload_tmp_dir within the PHP Language forums, part of the PHP Programming Forums category; Hi I am new and trying to learn php. I am trying to use some of the scripts in the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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" .. .. .. ********* 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 ) ) |
|
|||
|
mike 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" > . > . > . > ********* > 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 > ) > > ) > The first question is - which configuration file does phpino() say it's using? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On Sat, 08 Mar 2008 20:11:16 +0100, mike <spammesillt@junkmail.com> wrote:
> 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 = > upload_tmp_dir="C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\upload" I prefer to use '/' instead of '\'. PHP understands this, and it avoids those pesky 'is this slash escaping something or not?'. > 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. Indeed, upload_tmp_dir is PHP_INI_SYSTEM: "Entry can be set in php.ini or httpd.conf", so NO .htaccess or ini_set(). > Q1: How do I set the temporary upload file 'upload_tmp_dir' in windows > XP. You shouldn't need it, if nothing is set Windows default tmp dir is used, which usually saves you a lot of headaches. If you change the path in php.ini, and phpinfo() reports it not being set: 1) Check wether you have restarted your webserver (I assume Apache? httpd -k restart) 2) Check phpinfo() for the actual php.ini file used, it might not use the one you think. > 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) The tmp_name is automatically created by PHP for you on a succesfull upload, it's name is not important, it's just there in the $_FILES array.. > <form enctype="multipart/form-data" > action="http://localhost/php/upload.php" method="POST"> Enctype & post, check & OK. > <!-- MAX_FILE_SIZE must precede the file input field --> > <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> Nice gadget, don't rely on it. > Send this file: <input name="userfile" type="file" /> File input, check & OK. > if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { I'd check for errors first.... > echo "File is valid, and was successfully uploaded.\n"; > } else { > echo "Possible file upload problem\n"; > } > print_r($_FILES); > [userfile] => Array > ( > [error] => 6 UPLOAD_ERR_NO_TMP_DIR indeed... <http://nl2.php.net/manual/en/features.file-upload.errors.php> Can you write in your tmp directory with PHP? -- Rik Wasmus |
|
|||
|
Jerry Stuckle wrote:
> mike 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" >> . >> . >> . >> ********* >> 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 >> ) >> >> ) >> > > The first question is - which configuration file does phpino() say it's > using? > Hi Jerry, Configuration File (php.ini) Path C:\WINDOWS however when I look in the windows directory there is no php.ini file. Mike |
|
|||
|
Jerry Stuckle wrote:
> mike 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" >> . >> . >> . >> ********* >> 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 >> ) >> >> ) >> > > The first question is - which configuration file does phpino() say it's > using? > Hi Jerry, Configuration File (php.ini) Path C:\WINDOWS But when I look in the windows directory, I do not find a php.ini file. |
|
|||
|
mike wrote:
> Jerry Stuckle wrote: >> mike 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" >>> . >>> . >>> . >>> ********* >>> 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 >>> ) >>> >>> ) >>> >> >> The first question is - which configuration file does phpino() say >> it's using? >> > > Hi Jerry, > > Configuration File (php.ini) Path C:\WINDOWS > > however when I look in the windows directory there is no php.ini file. > > Mike > OK, so it's using a default file. The easiest way right now to change that is to put your php.ini file in c:/windows. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Rik Wasmus wrote:
> >> Q1: How do I set the temporary upload file 'upload_tmp_dir' in >> windows XP. > > > You shouldn't need it, if nothing is set Windows default tmp dir is > used, which usually saves you a lot of headaches. If you change the > path in php.ini, and phpinfo() reports it not being set: > 1) Check wether you have restarted your webserver (I assume Apache? > httpd -k restart) > 2) Check phpinfo() for the actual php.ini file used, it might not use > the one you think. > > UPLOAD_ERR_NO_TMP_DIR indeed... > <http://nl2.php.net/manual/en/features.file-upload.errors.php> > > Can you write in your tmp directory with PHP? I am not sure how to do this I am fairly green to php. do you have a short test script that I can try. What is the default temp directory? C:/windows/temp Mike |
|
|||
|
Jerry Stuckle wrote:
> mike wrote: > >> Jerry Stuckle wrote: >> >>> mike 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" >>>> . >>>> . >>>> . >>>> ********* >>>> 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 >>>> ) >>>> >>>> ) >>>> >>> >>> The first question is - which configuration file does phpino() say >>> it's using? >>> >> >> Hi Jerry, >> >> Configuration File (php.ini) Path C:\WINDOWS >> >> however when I look in the windows directory there is no php.ini file. >> >> Mike >> > > OK, so it's using a default file. The easiest way right now to change > that is to put your php.ini file in c:/windows. > I see. When I do that I am assuming that it will use this php.ini file for everything. At the begining of the file the comments indicate that it should be possible to use the php.ini file in the working directory is there a way to to force php to look for it in the working directory? This way I can have a seperate setup for each web project. Thanks mike |
|
|||
|
>> Q1: How do I set the temporary upload file 'upload_tmp_dir' in >> windows XP. > > > You shouldn't need it, if nothing is set Windows default tmp dir is > used, which usually saves you a lot of headaches. If you change the > path in php.ini, and phpinfo() reports it not being set: > 1) Check wether you have restarted your webserver (I assume Apache? > httpd -k restart) > 2) Check phpinfo() for the actual php.ini file used, it might not use > the one you think. > Buy the way I am using windows IIS not Apache (maybe someday) Mike |
|
|||
|
Jerry Stuckle wrote:
> mike wrote: > >> Jerry Stuckle wrote: >> >>> mike 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" >>>> . >>>> . >>>> . >>>> ********* >>>> 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 >>>> ) >>>> >>>> ) >>>> >>> >>> The first question is - which configuration file does phpino() say >>> it's using? >>> >> >> Hi Jerry, >> >> Configuration File (php.ini) Path C:\WINDOWS >> >> however when I look in the windows directory there is no php.ini file. >> >> Mike >> > > OK, so it's using a default file. The easiest way right now to change > that is to put your php.ini file in c:/windows. > OK I placed the php.ini file in the c:/windows directory but phpino() still reports 'upload_tmp_dir' as unset. Do I need to stop and restart the IIS web server. Thanks mike |
![]() |
| Thread Tools | |
| Display Modes | |
|
|