View Single Post
Old 08-22-2004, 11:18 PM   #1 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Loading Binary Data

Hi,

I had a problem loading an image into my mysql database the codes are as follows:

Code:
<html>
<head><title>Load Pic to MySQL Database</title></head>
<body>

<?php
// code that will be executed if the form has been submitted:

if ($submit) {

    // connect to the database
  
    MYSQL_CONNECT("192.168.x.x","sqldb","passwd");
    mysql_select_db("mydb");

    $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

    $result=MYSQL_QUERY("INSERT INTO pic201 (crewcode,pic,filename,filesize,filetype) ".
        "VALUES ('$form_crewcode','$data','$form_pic','$form_data_name','$form_data_size','$form_data_type')");

    $id= mysql_insert_id();
    print "<p>This file has the following Database ID: <b>$id</b>";

    MYSQL_CLOSE();

} else {

    // else show the form to submit new data:
?>

<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
    Crew Code:<br>
    <input type="text" name="form_crewcode"  size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <br>File to upload/store in database:<br>
    <input type="file" name="form_data"  size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>

<?php
Loading loadpic.php on the browser produces:

This file has the following Database ID:0

No errors appeared when clicking the submit button.

However, whenever I view the image it says:

File Name | Description | File size | File Type
blank | /tmp/phpu9S2hk | 0KB

The binary loading script does not "properly load" the image file.

In fact, the File Name appeared black

What should I do to resolve this?

Iam using mysql-4.0.20-1 and php 4.3.8-1 and Iam loading the binary (image) file from a windows machine.

Hope you can help me.

Thanks and more power.
infinite_root is offline   Reply With Quote