Can someone help please. I have followed a script (see below)from a book to allow users to upload images to a mysql database. I keep getting the following error.
Warning: open_basedir restriction in effect. File is in wrong directory in /home/myusername/public_html/test_handle.php on line 48
Warning: fopen("/tmp/phpJziNzi","r") - Operation not permitted in /home/*********/public_html/test_handle.php on line 48
File open failed!
Here is my script
include('***********');
$UPLOAD_TYPES['GIF'] = 1;
$UPLOAD_TYPES['JPG'] = 1;
$UPLOAD_TYPES['JPEG'] = 1;
$UPLOAD_SIZES['max'] = 40000;
$UPLOAD_SIZES['min'] = 0;
//Verify the file size and type
$intResult = verify_uploaded_file($HTTP_POST_FILES['upload_file']['name'],
$HTTP_POST_FILES['upload_file']['size']);
//The file does not meet criteria
if ($intResult != 1)
{
$msg_base = $HTTP_POST_FILES['upload_file']['name'] . ' is unacceptable.
';
//DIE WITH ERROR MESSAGE
if ($intResult == -1){
die ($msg_base . 'Reason: File size out of allowed range. ');
}
elseif ($intResult == -2){
die ($msg_base . 'Reason: File type not allowed. ');
}
}
//The file met criteria - verify and put in database
if (! is_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name']))
{
die("you didn't upload a file!");
}
else
{
//open file and store in $file_contents
$file = fopen($HTTP_POST_FILES['upload_file']['tmp_name'], 'r') or die("File open failed!");
$file_contents = fread($file,
filesize($HTTP_POST_FILES['upload_file']['tmp_name']))
or die("Can't read!");
fclose($file);
// Escape strange characters
$file_contents = AddSlahes($file_contents);
//put file in database
mysql_connect(MYSQL_HOST,MYSQL_USER, MYSQL_PASS) or die ("Unable to connect");
mysql_select_db(MYSQL_DBASE) or die ("Unable to select DB.");
mysql_query($SQL = "INSERT INTO $TableName SET graphic ='$file_contents'")
or die("MySQL Query Error: " . mysql_error() . "
"
. "The SQL was: $SQL
");
mysql_close();
echo $HTTP_POST_FILES['upload_file']['name'] . ' was uploaded successfully.';
}
function verify_uploaded_file($strName, $intSize)
{
if ($intSize < $GLOBALS['UPLOAD_SIZES']['min'] || $intSize > $GLOBALS['UPLOAD_SIZES']['max'])
{
return -1;
}
$arrSegments = split('[.]', $strName);
$strExtension = $arrSegments[count($arrSegments) -1];
if ($GLOBALS['UPLOAD_TYPES'][strtoupper($strExtension)] != 1){
return -2;
}
return 1;
}
?>


