Re: file upload problem



mike wrote:
Hi,

Thank you to those that helped with the php.ini problem.

Now my real problem, I am very new to php. I am trying to learn about uploading files with php. I made a simple form script and and file up load script. Right now I am really just tring to move a file from one directory to another.

The form script gets the file name correctly and seems to pass it to the upload script correctly. However the movement of the file to the new directory never occurs because of an error Value: 6; Missing a temporary folder. However, if I look at the phpinfo() results I see that 'upload_tmp_dir' directory is set to a valid directory (same one that is in the php.ini file). Also, if I echo ini_get('upload_tmp_dir') I see
the same valid directory. So I am not sure why the error.

Note also if I uncomment the line:
//$tmp_file = $_FILES['userfile']['tmp_name']

in the upload script, the process seems to abort I just get a blank browser screen.

Q:Any ideas on why the temp directory path/ file name is not getting set

Thanks
Mike


My scripts are below:
*****************************************
File Form
***************

<html>
<body>

<?php echo '<p>Hello World</p>'; ?>


<?php

$b=ini_get('upload_tmp_dir');
$c=ini_get('SMTP');

echo "temp dir is = $b <br /> ";
echo "localhost is $c = <br /><br />";

?>

<!-- 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>

</body>
</html>

**********************************************
File Upload
******************

<html>
<body>

<?php

$b=ini_get('upload_tmp_dir');
$c=ini_get('SMTP');

echo "temp directory is = $b <br /> ";
echo "localhost is = $c <br /><br />";

$uploaddir = 'C:\Inetpub\wwwroot\php_testfiles\upload\\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
//$tmp_file = $_FILES['userfile']['tmp_name']

echo "uploaddir = $uploaddir <br />";
echo "uploadfile = $uploadfile <br />";
//echo "$tmp_file = $tmp_file <br /><br />";

echo '<pre>';

echo ini_get('upload_tmp_dir');

echo 'Here is some pre debugging info:<br />';
print_r($_FILES);


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

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

print "</pre>";

?>

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

Results
******************
temp directory is = C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\upload
localhost is = localhost

uploaddir = C:\Inetpub\wwwroot\php_testfiles\upload\
uploadfile = C:\Inetpub\wwwroot\php_testfiles\upload\optoutalrt.pdf

C:\DOCUME~1\MIA-KI~1\LOCALS~1\Temp\php\uploadHere is some pre debugging info:Array
(
[userfile] => Array
(
[name] => optoutalrt.pdf
[type] =>
[tmp_name] =>
[error] => 6
[size] => 0
)

)
Possible file upload attack problem
Here is some post debugging info:Array
(
[userfile] => Array
(
[name] => optoutalrt.pdf
[type] =>
[tmp_name] =>
[error] => 6
[size] => 0
)

)


Does your webserver userid have write access to the temporary directory?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • NOCC Webmail <= 1.0 multiple vulnerabilities
    ... "NOCC is a webmail client written in PHP. ... remote code execution, there are two ways of execute arbitrary code on ... is defined in conf.php, by default no path is defined, but script suggests ... echo nl2br); ...
    (Bugtraq)
  • Re: PHP-file upload problem and upload_tmp_dir
    ... I am trying to use some of the scripts in the php manual to upload a file. ... It calls and posts to the file processing script correctly. ... echo ''; ...
    (comp.lang.php)
  • Re: [PHP] Help with an error...
    ... I am currently working on a php script that will be called by cron. ... echo 'This could not be display due to a system error. ...
    (php.general)
  • Re: PHP-file upload problem and upload_tmp_dir
    ... I am trying to use some of the scripts in the php manual to upload a file. ... It calls and posts to the file processing script correctly. ... echo ''; ...
    (comp.lang.php)
  • Re: PHP-file upload problem and upload_tmp_dir
    ... I am trying to use some of the scripts in the php manual to upload a file. ... It calls and posts to the file processing script correctly. ... echo ''; ...
    (comp.lang.php)