Re: file upload problem



Jerry Stuckle wrote:
mike wrote:

Jerry Stuckle wrote:

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?

Jerry,

Good question. I am working in that userid. So I installed the webserver in this userid and I installed php in this userid. also the temp directory in the php.ini file, reported in phpinfo(),and echoed back with ini_get('upload_tmp_dir') was created by the php install. So I am guessing that the server should have read/write permissions.


Not necessarily. The userid you installed PHP with is not the one used by the webserver.

I do not know if IUSR_XXXX has or needs permission.


Whether it has it or not, I don't know. But it needs it.

Here I am a bit stuck, When I right click on folder I am only given the option of local sharing or network sharing, I can not remember how to check which individual users have what permissions to acess a directory.
in XP.

Thanks
Mike


Sorry, I use W2K, 2.3K and Linux, but not WXP. I don't remember. You could try one of the Microsoft newsgroups.

Ok I aborted using the upload_tmp_dir that was set in the php.ini file.
The original php.ini has two places where the 'upload_tmp_dir' is set. One is commented out:
..
..
..
; 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"
..
..
..

I tried to to set the permissions on the C:\...\php\upload
directory. I add full control for IUSER_XXXX, IWAM_XXXX,
NETWORK SERVICES. No help same error Value: 6; Missing a
temporary folder.

I gave up and decided to creat a new temp directory. So I commented out the second assignment of C:\...\php\upload, UNcommented the first assignment, and set it to be the new temp directory.

upload_tmp_dir = "c:\tempphp"

I restarted the server and ran the script.
This killed the error. My output is below. The file array now
show a name for the file 'type', 'tmp_name', 'size" and most importantly it show and 'error' code of 0. This indicates no proplems with the upload.

However, I still have one problem. No file appeared in the upload directory. php reports everthing went fine, but no file shows up.
Just to make sure it did not get transfered some where strange, I scaned the whole computer. It only resides in the original directory.

Any thoughts on the reson why the file did not get moved? It looks like the condition in the if/else statement is failing because the 2nd echo
is getting printed.

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";
}

That means the move_upload_file() is failing to move the file. Any thoughts on why this might be happening.

Thanks
mike


***********************
script output results
***********************

temp directory is = C:\tempphp
localhost is = localhost

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

C:\tempphpHere is some pre debugging info:
Array
(
[userfile] => Array
(
[name] => newsletter_081507.pdf
[type] => application/pdf
[tmp_name] => C:\tempphp\phpCD.tmp
[error] => 0
[size] => 110435
)

)
Possible file upload problem
Here is some post debugging info:Array
(
[userfile] => Array
(
[name] => newsletter_081507.pdf
[type] => application/pdf
[tmp_name] => C:\tempphp\phpCD.tmp
[error] => 0
[size] => 110435
)

)
**********************************************
.



Relevant Pages