Help - Search - Members - Calendar
Full Version: Error Trying To Upload From A Script
Zymic Webmaster Forums > Zymic Free Web Hosting > Zymic Free Web Hosting - General Discussion & Help
Mighty Balrog
Hello I am trying to upload jpg images to the server through a custom script.

Here is the invocation line of the custom function I created:

CODE
uploadImage( "my_pix.jpg", "image/jpeg", 500000, "./images/", 'thumb-image' );


Here is the HTML used.

CODE
<form enctype="multipart/form-data" action="/hailee/admin.php?page=9" method="POST">
      <td><input type="text" name="img-path" value="" /></td>
      <td><input type="text" name="thumb-path" value="" /></td>
      <td><input type="text" name="caption" value="" /></td>

      <td><input type="text" name="alt" value="" /></td>
      <td><input type="submit" value="add" name="submit_add" /></td>
      <br />
   </tr>
   <tr>
      <td colspan="2" >Upload Full Picture (.jpg) : <input type="file" name="full-image" /></td>
      <td colspan="2" >Upload Thumbnail Picture (.jpg) : <input type="file" name="thumb-image" /></td>
      <td><input type="button" value="Populate" onclick="populate()" /></td>

      </form>


This is the custom function definition:

CODE
// ***********************************************************
// ** uploadImage() - function
// **
// **     This function will upload an image to sever it requires:
// **    name = { name to call image as name.ext }
// **             or "OFF" if you dont want to change the name.
// **    type = { ext type allowed: image/ext }
// **             it will exect an array of allowed image types in the "image/ext" format.
// **    maxsize = { a number in bytes that is allowed }
// **    path = { a path to the directory to upload image to }
// **    formName = { name of the <input type="file"> field }
// **   optional chmod = { file permisions for the file that is uploaded defaults to 644 or lrw-r-r
// **
// ***********************************************************

function uploadImage ( $name, $type, $maxsize, $path, $formName, $chmod = 0644 )
{
    $tempPic = basename( $_FILES[$formName]['name'] );
    $extion = substr( $tempPic,strrpos($tempPic,"."),strlen($tempPic)-strrpos($tempPic,"."));
    $isMatch = false; // this varible is use to validate image types
    
    // Checking to see if user wants a specific name used
    if( strcmp( strtolower( $name ), "off") == 0 )
    {    
        $picName = $tempPic;
    }
    else
    {
        // check to see if user explisitly chose an ext
        if ( strpos( $name, ".") )
        {
            $picName = $name;
        }
        // if not then attach extention that was originally associated with the file
        else
        {
            $picName = $name . $extion;
        }
    }
    
    // check to see if an Array was supplied for multiple types
    if( is_array( $type ))
    {
        foreach ($type as $value)
        {
            // if the image type matchs one of the types supplied then set the flag
            if( $value == $_FILES[$formName]['type'] )
            {
                $isMatch = true;
            }
        }
    }
    else
    {
        // $type is not an array; check to see if it matches the image type
        if ( $type == $_FILES[$formName]['type'] )
        {
            $isMatch = true;
        }
    }
    
    // check if image type matched if not exit function
    if ( !$isMatch )
    {
        $errorMessage = "Wrong File Type";
        return $errorMessage;
    }
    
    // check to see if image is with in allowed memory size
    if ( $_FILES[$formName]['size'] > $maxsize && $maxsize > 0 )
    {
        $errorMessage = "File exceeds Maximum Size Allowed";
        return $errorMessage;
    }
    
    // set path up with the proper name
    $path .= $picName;
    // move the file from temp directory to the real directory
    if( move_uploaded_file($_FILES[$formName]['tmp_name'], $path) )
    {
        chmod( $path, $chmod );
        return $extion;
    }
    else
    {
        $errorMessage = "Error: could not move the file from temporary directory ";
        return $errorMessage;
    }
}


here is the error message that I am getting:

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/www/tmp/phpnreTU0) is not within the allowed path(s): (/www/com/m/y/h/myheinrichsfamily/htdocs) in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81

Warning: move_uploaded_file(./images/hailee_011_thumb.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/www/tmp/phpnreTU0' to './images/hailee_011_thumb.jpg' in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81

*** my website has a customer domain setup (myheinrichsfamily.com) ***

any and all help would be appreciated.
Mighty Balrog
QUOTE
Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/www/tmp/phpnreTU0) is not within the allowed path(s): (/www/com/m/y/h/myheinrichsfamily/htdocs) in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81

Warning: move_uploaded_file(./images/hailee_011_thumb.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/www/tmp/phpnreTU0' to './images/hailee_011_thumb.jpg' in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81


I have done some research and have discovered why I am getting this warning and unable to use the script and <input type="file" name="upload" /> tag with php. The open_basedir restriction in effect. File(/www/tmp/phpnreTU0) is not within the allowed path(s): (/www/com/m/y/h/myheinrichsfamily/htdocs) states that the temporary path set in the php environment variables is set outside the path my scripts are allowed to access files which is /www/com/m/y/h/myheinrichsfamily/htdocs. This renders the <input type="file" name="upload" /> tag virtually worthless. As Php's upload functions only place the uploads in a tmp folder and then you must move them from that folder to your designated folder.

I have looked for alternatives but have been unable to find one.

I have found one thread on this forum that addresses this issue, but the resolution is not apparent. I think the administrator did something to allow this to be resolved on the posted thread.
Thread Addressing the Issue!
The admin was Ed.
If anyone knows of an alternative way of uploading images I would appreciate any help or links to scripts.

The reason for the image upload function is so that I can make a Control Panel (CRM) that allows me to manage my content without having to manually edit image uploads and edit databases it will also allow my wife to make changes when she needs to.
Phoenyx
Are you using own domain name (for example mysite.com) or zymic domain (mysite.uuuq.com)? I have such problem only using my own domain and there is no warning using uuuq.com. So if you using script for administration purposes only, you can access you script through zymic domain..
Phoenyx
QUOTE(Mighty Balrog @ Aug 21 2009, 11:26 AM) *
Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/www/tmp/phpnreTU0) is not within the allowed path(s): (/www/com/m/y/h/myheinrichsfamily/htdocs) in /www/uuuq.com/m/b/6/mb6development/htdocs/hailee/image_functions.php on line 81


temporary file phpnreTU0 is located in the temporary folder /www/tmp
when trying to move this file to the folder /www/com/m/y/h/myheinrichsfamily/htdocs php shows warning, because this path is not located in your home dir /www/uuuq.com/m/b/6/mb6development/htdocs
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.