0

I am trying to upload files in dynamically created folder. It is working properly in my localhost but on server it is showing me error. The Error is:-

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/tmp/php323kcy) is not within the allowed path(s): (/home/) in /home/..../public_html/www..com./.../controller/add-product-process.php on line 83

My Php code is Here

<?php



include 'connection.php';

if(isset($_POST['product_name']) && ($_POST['category'])&& ($_POST['sub-category']) && ($_POST['product_qty']) && ($_POST['price']) && ($_POST['description']) && ($_POST['weight']))

{

 $pname = $_POST['product_name'];



 $category = $_POST['category'];

 $scategory = $_POST['sub-category'];

 $qty = $_POST['product_qty'];

 $price = $_POST['price'];

 $desc = $_POST['description'];

 $dp=$_POST['dp'];

 $offer= $_POST['offer'];

 $size=$_POST['size'];

 $weight=$_POST['weight'];

if(isset($_POST['color']))

{

$color=$_POST['color'];

}

else

{

$color = "N/A";

}

$query3 = mysql_query("select category_id from category where category_name='$category'");

$row3 = mysql_fetch_array($query3);



$query4 = mysql_query("select sub_category_id from sub_category where sub_category_name='$scategory'");

$row4 = mysql_fetch_array($query4);



$query1 = mysql_query("select product_id from stock");

while ($row = mysql_fetch_row($query1)) {

    $id = $row[0];

}

$str1 = substr($id, 2, 5);

if (($str1 >= 1) && ($str1 < 9)) {

    $str1++;

  echo  $new_id = "RD0000" . $str1;

} else if (($str1 >= 9) && ($str1 < 99)) {

    $str1++;

   echo $new_id = "RD000" . $str1;

} else if (($str1 >= 99) && ($str1 < 999)) {

    $str1++;

    echo $new_id = "RD00" . $str1;

} else if (($str1 >= 999) && ($str1 < 9999)) {

    $str1++;

   echo $new_id = "RD0" . $str1;

} else if (($str1 >= 9999) && ($str1 < 99999)) {

    $str1++;

   echo $new_id = "RD" . $str1;

} else {

    echo 'Error: Contact PSSP.';

}



$dirPath = "../products/$new_id";

$imgpath = "products/$new_id";

$result = mkdir($dirPath, 0755);

if ($result == 1) {

    echo $dirPath . " has been created";

} else {

    echo $dirPath . " has NOT been created";

}

define ("FILEREPOSITORY","../products/$new_id");

for ($i = 0; $i < sizeof($_FILES['uploadfile']['name']); $i++) {        

echo $path=$new_id.$i;

$filename = $dirPath.$path.'.jpeg';

           if (is_uploaded_file($_FILES['uploadfile']['tmp_name'][$i])) 

            {

            $filename2 = $imgpath."/".$path.'.jpeg';

            $fl[$i]=$filename2;

                        if ($_FILES['uploadfile']['type'][$i] != "image/jpeg") 

              {

                 echo "<p>Must be Image file.</p>";

              } 

             else if(file_exists($filename))

                {

              echo "already exist";

               }



              else 

                {

         //$name = $_POST['corname'];

         $result = move_uploaded_file($_FILES['uploadfile']['tmp_name'][$i], FILEREPOSITORY."/$path.jpeg");
            echo "result is".$result;
         if ($result == 1) 

            {

            echo "<p>File successfully uploaded.</p>";

            }

            else 

            {

            echo "not uploaded";

            }

            }

            }

            }

                        $files=implode(',',$fl);



> 
$query2 = mysql_query("insert into stock(product_id,product_name,category,sub_category,quantity,price,dp,offer,description,image,size,weight,color)values('$new_id','$pname','$row3[0]','$row4[0]','$qty','$price','$dp','$offer','$desc','$files','$size','$weight','$color')");

if (!$query2) {

    echo mysql_error();

} else {

    ?>

    <script language="javascript" type="text/javascript">

        // Print a message

        alert('Successfully Added..');

        // Redirect to some page of the site.

        window.location = '../add-product.php';

    </script>

    <?php



}

}

else

{

    echo "Error in page...";

}

?>

Please aware me about the problem..

Thanks in advance

Bushra Shahid
  • 781
  • 7
  • 20
  • 1
    Just add the surrounding of the code you facing problem. This is too much too code to read & trace your issue. – Rikesh Apr 24 '13 at 13:35
  • 1
    [1]: http://stackoverflow.com/questions/1846882/open-basedir-restriction-in-effect-file-is-not-within-the-allowed-paths – Useless Intern Apr 24 '13 at 13:42
  • i am facing problem in move_upload_files(); it's showing me error on server not in localhost.. in localhost this code is working properly. – Bushra Shahid Apr 24 '13 at 13:45
  • that means that the code is ok, probably on your remote server php don't have permissions to write or access that folder or something is wrong with the configuration – aleation Apr 24 '13 at 13:51
  • I think the problem is somewhat similar to http://stackoverflow.com/questions/1846882/open-basedir-restriction-in-effect-file-is-not-within-the-allowed-paths – Sudo Reboot Apr 24 '13 at 13:53

1 Answers1

0

Your hosting account is configured in such a way that PHP uploads are not functional:

  • Apache stores temporary files in /tmp.
  • PHP is not allowed to read files outside /home/ (funnily enough, it's apparently allowed to read files from other users).

The first path is controlled with the upload_tmp_dir directive. The second path is controlled with the open_basedir directive. As far as I know, both of them are global settings you aren't allowed to change.

You need to contact support and ask for help to get this fixed.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360