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>
<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;
}
}
// ** 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.
