cookseytalbott
03-01-2008, 06:22 PM
I am having problems getting PHP to upload files using move_uploaded_file() to any directory other then the root of the site.
I have some long established known working code that does this in a number of places and when I moved it to bluehost it failed.
I have contacted support but that has taken days and I need to do work on this contract soon.
You can see the result at:
http://www.rollinghillssoftware.com/test3.php
Here is the code:
// -----------------------------------------
// This sequence works...
// -----------------------------------------
$localPath = '/home/rollingh/';
$fileNameAndPath = $localPath . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $fileNameAndPath))
{
echo "File successfully uploaded to $fileNameAndPath\n";
}
else
echo "File upload to $fileNameAndPath - FAILED\n";
print_r($_FILES);
print "</pre>";
// -----------------------------------------
// This sequence fails...
// The directory /shared exists and has permissions set to 777
// -----------------------------------------
$localPath = '/home/rollingh/shared/';
$fileNameAndPath = $localPath . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $fileNameAndPath))
{
echo "File successfully uploaded to $fileNameAndPath\n";
}
else
echo "File upload to $fileNameAndPath - FAILED\n";
print_r($_FILES);
print "</pre>";
I have the MAX_SIZE set to 1000 and have been testing with a < 20 byte text file so the fail has nothing to do with size restrictions.
I made MAX_SIZE small for the purpose of this posting to prevent malicious overbyte.
To me it seems like a host specific problem as this snippet is pretty minimal and works on several other servers.
Anyone here have any suggestions on what is up with this ?
TIA and Cheers,
Cooksey
I have some long established known working code that does this in a number of places and when I moved it to bluehost it failed.
I have contacted support but that has taken days and I need to do work on this contract soon.
You can see the result at:
http://www.rollinghillssoftware.com/test3.php
Here is the code:
// -----------------------------------------
// This sequence works...
// -----------------------------------------
$localPath = '/home/rollingh/';
$fileNameAndPath = $localPath . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $fileNameAndPath))
{
echo "File successfully uploaded to $fileNameAndPath\n";
}
else
echo "File upload to $fileNameAndPath - FAILED\n";
print_r($_FILES);
print "</pre>";
// -----------------------------------------
// This sequence fails...
// The directory /shared exists and has permissions set to 777
// -----------------------------------------
$localPath = '/home/rollingh/shared/';
$fileNameAndPath = $localPath . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $fileNameAndPath))
{
echo "File successfully uploaded to $fileNameAndPath\n";
}
else
echo "File upload to $fileNameAndPath - FAILED\n";
print_r($_FILES);
print "</pre>";
I have the MAX_SIZE set to 1000 and have been testing with a < 20 byte text file so the fail has nothing to do with size restrictions.
I made MAX_SIZE small for the purpose of this posting to prevent malicious overbyte.
To me it seems like a host specific problem as this snippet is pretty minimal and works on several other servers.
Anyone here have any suggestions on what is up with this ?
TIA and Cheers,
Cooksey