error when uploading jpg image

hi,
why did this code that upload image to database gives me warning when I'm trying to upload jpg or png files?
the warning is :
Warning: fopen(E:/tmp/) [function.fopen]: failed to open stream: Permission denied in c:\program files\apache group\webroot\image uploadphp.php on line 17
Warning: fread(): supplied argument is not a valid stream resource in c:\program files\apache group\webroot\image uploadphp.php on line 17
large.jpg
but it does not do this when I'm uploading gif file!!
my code is :
<?php
require($_SERVER["DOCUMENT_ROOT"]."\config\kdem_db_config.php");
    $link = @mysql_connect($db_host, $db_user, $db_password);

    if (!$link) {
       die('Could not connect: ' . mysql_error());
    }
    else echo "Connection made";
    mysql_select_db($db_name,$link);
         $form_data = $HTTP_POST_FILES["userfile"]["tmp_name"];
//move it to some temp dir
         $base_name = "E:/tmp/".basename($form_data);
         move_uploaded_file($form_data, $base_name);
// read the file
         $data = addslashes(fread(fopen($base_name, "r"), filesize($base_name)));
//insert query
$imageName = basename($_FILES['userfile']['name']);
echo "$imageName";
        $query="insert INTO img_pg
                  VALUES ('$imageName','$data','{$HTTP_POST_FILES[userfile][size]}','{$HTTP_POST_FILES[userfile][type]}')";
                  mysql_query($query, $link) or die (mysql_error());
?>
the img_pg table structure is :
+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| img_name | varchar(100) | YES  |     | NULL    |       |
| img_data | longblob     | YES  |     | NULL    |       |
| img_size | varchar(60)  | YES  |     | NULL    |       |
| img_type | varchar(60)  | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
notice that I'm using php5 with mysql5 with windows xp.
Ameerh24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

akshah123Commented:
tgatif,

I believe the problem is that $base_name is blank for whatever the reason.

Can you try using
var_dump() to get following ...
         $form_data = $HTTP_POST_FILES["userfile"]["tmp_name"];
         var_dump($form_data);
//move it to some temp dir
         $base_name = "E:/tmp/".basename($form_data);
         var_dump($base_name);
         move_uploaded_file($form_data, $base_name);
0
Ameerh24Author Commented:
hi,
it looks strange .. when I upload jpg file I don't get it's $form_data !!
the output of uploading jpg image:
string(0) ""
string(7) "E:/tmp/"
Warning: fopen(E:/tmp/) [function.fopen]: failed to open stream: Permission denied in c:\program files\apache group\webroot\image uploadphp.php on line 23
Warning: fread(): supplied argument is not a valid stream resource in c:\program files\apache group\webroot\image uploadphp.php on line 23
large.jpg

but,when I upload gif file I can get it's $form_data
the output of uploading gif image:
string(26) "C:\WINDOWS\TEMP\php1D3.tmp"
string(17) "E:/tmp/php1D3.tmp"

what should I do, and what is the reason of this strange error?
Thanks
0
akshah123Commented:
Perhaps the file you are uploading has a size greater than allowed by your php as set in php.ini.

try this ...

<?php
require($_SERVER["DOCUMENT_ROOT"]."\config\kdem_db_config.php");
    $link = @mysql_connect($db_host, $db_user, $db_password);

    if (!$link) {
       die('Could not connect: ' . mysql_error());
    }
    else echo "Connection made";
    mysql_select_db($db_name,$link);

switch ($_FILES['userfile']['error']) {
   case: UPLOAD_ERR_OK
        break;
   case UPLOAD_ERR_INI_SIZE:
       throw new Exception("The uploaded file exceeds the upload_max_filesize directive (".ini_get("upload_max_filesize").") in php.ini.");
   break;
   case UPLOAD_ERR_FORM_SIZE:
       throw new Exception("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.");
   break;
   case UPLOAD_ERR_PARTIAL:
       throw new Exception("The uploaded file was only partially uploaded.");
   break;
   case UPLOAD_ERR_NO_FILE:
       throw new Exception("No file was uploaded.");
   break;
   case UPLOAD_ERR_NO_TMP_DIR:
       throw new Exception("Missing a temporary folder.");
   default:
       throw new Exception("An unknown file upload error occured");
}
         $form_data = $HTTP_POST_FILES["userfile"]["tmp_name"];
//move it to some temp dir
         $base_name = "E:/tmp/".basename($form_data);
         move_uploaded_file($form_data, $base_name);
// read the file
         $data = addslashes(fread(fopen($base_name, "r"), filesize($base_name)));
//insert query
$imageName = basename($_FILES['userfile']['name']);
echo "$imageName";
        $query="insert INTO img_pg
                  VALUES ('$imageName','$data','{$HTTP_POST_FILES[userfile][size]}','{$HTTP_POST_FILES[userfile][type]}')";
                  mysql_query($query, $link) or die (mysql_error());
?>
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Ameerh24Author Commented:
any help on that trouble, please?
0
Ameerh24Author Commented:
oh sorry wasn't pay attention for your post!
0
Ameerh24Author Commented:
hi,
I've got this message error:
Fatal error: Uncaught exception 'Exception' with message 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.' in c:\program files\apache group\webroot\image uploadphp.php:20 Stack trace: #0 {main} thrown in c:\program files\apache group\webroot\image uploadphp.php on line 20

and my html form code is :
 <form enctype="multipart/form-data" action="image uploadphp.php" method="POST">

    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="99999999" />

    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />

    <input type="submit" value="Send File" />
</form>

and my jpg file size is : 45.8 KB

so, how could it be?!!(45 is not bigger than 99999999)
any help on that trouble, please?
0
akshah123Commented:
Well, try taking out the
<input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
altogether.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ameerh24Author Commented:
thanks alot akshah123,
it worked fine..
just one more thing, please..
does the value prop. in <input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
denotes to the max file size in bits,bytes,kb?

0
akshah123Commented:
>>>does the value prop. in <input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
Bytes...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.