skip to Main Content

I want to upload to directory ‘Uploads’ which is one step above the root (using Plesk).

Could anyone tell me why the files won’t upload there? Permissions have been give to Uploads as 777.

ob_start();

session_start();

$extensions = array("jpg", "png","jpeg", "gif", "zip", "rar", "swf", "tiff", "bmp", "txt", "fla", "7z", "tar", "gz", "iso", 

"dmg", "mp3", "wav", "m4a", "aac", "doc", "docx", "xls", "rtf", "ppt", "bsd", "exe", "psd", "c4d", "pdf", "dwg", "max", "ipa", 

"vtf", "iam", "ipt", "flv", "cap", "scr");
$maxsize = 104288000;
$server = "http://www.andre.com";

$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];

$random = md5(uniqid(rand(), true));
$random = substr($random, 0, 20);

if (!$name || !$temp || !$size)
{
   echo "Go back and select a file.";
   exit();
}

foreach ($_FILES as $file)
{
 if ($file['tmp_name'] != null) 
 {
    $thisext1=explode(".", strtolower($file['name']));
    $thisext=$thisext1[count($thisext1)-1];
  if (!in_array($thisext, $extensions))
  {
    echo "That file type is not allowed.";
   exit(); 
  }
 }
}

if ($size > $maxsize)
{
   echo "File size too big.";
   exit();
}


$destination = "../Uploads/" . $random ;
mkdir($destination);
move_uploaded_file($temp, $destination."/".$name);

$final = $server."/".$destination."/".$name;

Looking at

 $destination = "../Uploads/" . $random ;

in particular which is found in /var/www/vhosts/example.com/Uploads.

4

Answers


  1. Chosen as BEST ANSWER

    I had a open_basedir error as user973... suggested.

    Solved by creating vhost.conf in:

    /var/www/vhosts/site.com/conf

    Added in the following:

    <Directory /var/www/vhosts/site.com/httpdocs/>
    php_admin_value open_basedir    "/var/www/vhosts/uploadvillage.com/httpdocs:/tmp:/var/www/vhosts/site.com/Uploads"
    </Directory> 
    

    and then rebuilt apache config with:

    [root@server1 ~]# /usr/local/psa/admin/bin/httpdmng --reconfigure-all
    

  2. can be open_basedir or safe_mode restrictions, also check user privileges

    Login or Signup to reply.
  3. If you’re trying to upload from the root to Uploads, you don’t use ../Uploads/ to reference that directory. It’s either ./Uploads/, or just Uploads/.

    ../ references the directory above the current directory, which in your case would be /var/www/vhosts/.

    Login or Signup to reply.
  4. Try anchoring your relative path by using $_SERVER['DOCUMENT_ROOT']:

    $destination = $_SERVER["DOCUMENT_ROOT"] . "/../Uploads/" . $random;
    

    Alternatively, you can use a path relative to the current PHP script using __DIR__ (or dirname(__FILE__) if you are using PHP 5.2):

    $destination = __DIR__ . "/../Uploads/" . $random;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search