Jump to content

Recommended Posts

Ok, in development, this worked just fine. I can see why but not the exact reason. In this script, to find the directory to upload to it uses (relative paths, i think is the term).

 

the culprit...

 

// Uploads folder name
$folder = $_POST['folder'] . "/";

// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the directory that will recieve the uploaded files
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . $folder;

// make a note of the location of the upload form in case we need it
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

// make a note of the location of the success page
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.php?g=success';

// name of the fieldname used for the file in the HTML form
$fieldname = 'file';



// Now let's deal with the upload

// possible PHP upload errors
$errors = array(1 => 'php.ini max file size exceeded', 
                2 => 'html form max file size exceeded', 
                3 => 'file upload was only partial', 
                4 => 'no file was attached');

// check the upload form was actually submitted else print form
isset($_POST['submit'])
or error('the upload form is neaded', $uploadForm);

// check for standard uploading errors
($_FILES[$fieldname]['error'] == 0)
or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

// check that the file we are working on really was an HTTP upload
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
or error('not an HTTP upload', $uploadForm);

// validation... since this is an image upload script we 
// should run a check to make sure the upload is an image
@getimagesize($_FILES[$fieldname]['tmp_name'])
or error('only image uploads are allowed', $uploadForm);

// make a unique filename for the uploaded file and check it is 
// not taken... if it is keep trying until we find a vacant one
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}

// now let's move the file to its final and allocate it with the new filename
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
or error('receiving directory insuffiecient permission', $uploadForm);

 

The issue is the $uploadsDirectory variable and more specifically the $_SERVER['DOCUMENT_ROOT'] variable.

 

this is the error it gives...

 

PHP Error Message

 

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/local/apache/htdocs/admin/landscapes/HR/1251099102-verification_seal.gif) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp) in /home/a5584074/public_html/admin/upload.processor.php on line 55

 

Upload failure

An error has occured: receiving directory insuffiecient permission... The upload form is reloading

 

I contacted the server helpdesk to see if there was a restriction on that method but ofc they said the only reason I would get that error is if it is pointing to a directory that is not in my account.

This is simply not the case, and in fact, all of the directories and file in the account were CHMODed to 777. I thought that might be the issue. No dice.

 

So my only conclusion is the $uploadsDirectory is pointing to something other than root/public_html/...path_to_dir

 

is there a better way to point to the directory i need?

 

If I am way off the mark then tell me.

Yes, but did you inform your web host that $_SERVER['DOCUMENT_ROOT'] is not returning the proper value for your account, which should be - /home/a5584074/public_html It is apparently returning - /usr/local/apache/htdocs

 

Some web hosts don't setup virtual hosts correctly.

 

In the meantime, you can set $_SERVER['DOCUMENT_ROOT'] to the proper value at the start of your script (it is just a variable.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.