Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Upload Problem

Status
Not open for further replies.

brogan

Technical User
Oct 7, 2003
44
0
0
GB
I have taken the code from and tested it on my web host ("File is valid, and was successfully uploaded.")However, when I check the "upload" directory seen below the file is not there?

Code:
$uploaddir = 'e:\domains\s\mydomain.co.uk\user\htdocs\upload';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

Mark
 
its definately arrived in the tmp directory ?

afer that, this code takes over;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

try echoing the $uploadfile variable to the page, to check the path corresponds with what you believe it to be.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for your response! I've echoed out the $uploadfile variable and get the following:

e:\domains\s\mydomain.co.uk\user\htdocs\uploadimage.gif

The forward slash is missing?
 
Thanks for your reply Jeff. This gives me a parse error though

Mark
 
upload dir = e:\domains\s\mydomain.co.uk\user\htdocs\upload

yet $uploadfile returns

e:\domains\s\mydomain.co.uk\user\htdocs\uploadimage.gif

upload dir should be set as

$uploaddir = 'e:\domains\s\mydomain.co.uk\user\htdocs\upload\'; <--trailing \

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hi, I have also tried this and it still produces a parse error

Mark
 
$uploaddir = 'e:\domains\s\mydomain.co.uk\user\htdocs\upload\';

TRY 'e:/domains/s/mydomain.co.uk/user/htdocs/upload/';

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
That works but the file still does not appear in the folder?

Mark
 
what does echo $uploadfile give now ?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Here's what's printed:

File is valid, and was successfully uploaded.
e:/domains/s/mydomain.co.uk/user/htdocs/upload/image.gif
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => abi global.txt
[type] => text/plain
[tmp_name] => C:\WINDOWS\TEMP\php570.tmp
[error] => 0
[size] => 17
)

)

I can only think there's some sort of permission issue with the web host?

Thanks

Mark
 
sorry, error above: name => image.gif
 
Ok, your code is a bit thin, post *alot* more code.


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Here's the submit form:

Code:
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload2.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>

And the rest:

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

$uploaddir = 'e:/domains/s/mydomain.co.uk/user/htdocs/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 attack!\n";
}
echo $uploadfile;
echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>
 
mm works perfectly under linux, does phpinfo() report file_uploads as 1 or 0 ?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
file_uploads is "on" for both Local and Master values.

Mark
 
Have to agree with your thought on permissions then. Not sure why tho as you've obviously got write perms to the temp dir.
can you get php to write/copy anything into the upload directory?

for example : test.php
Code:
<?
echo basename($_SERVER['PHP_SELF'])."<br>";
if(!copy(basename($_SERVER['PHP_SELF']),'upload/test.txt'))
{
echo "Copy failed";
}
else
{
echo "ok I think <a href=upload/test.txt>test.txt</a>";
}
?>

see ifthis can copy itself from your htdocs folder to the upload folder when run.

if it can't, its permissions on the upload folder, if it can, its read permissions on the temp file at best guess.


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top