Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-23-2004, 12:18 AM   #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
Old 08-23-2004, 05:11 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
First, I wouldn't rely on the `register_globals` setting being on.

eg: Don't use $form_crewcode, use $_POST['form_crewcode']. Also use the $_FILES array.

File upload docs

Also, I wouldn't add slashes to the binary data either.

PHP Code:
// don't add any slashes to binary data.
   
$file $_FILES['form_data']['tmp_name'];
   
$data fread(fopen($file'r'), filesize($file)); 
(your data type in mysql is a blob right?)

-r
idx is offline   Reply With Quote
Old 08-23-2004, 11:14 PM   #3 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Quote:
Originally posted by idx
First, I wouldn't rely on the `register_globals` setting being on.

eg: Don't use $form_crewcode, use $_POST['form_crewcode']. Also use the $_FILES array.


Sorry for my ignorance could you pls. Show me how to do it? I'm really new with php and just trying to work to it though.


Quote:
(your data type in mysql is a blob right?)

-r
Yes, Iam using longblob.
infinite_root is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
php script that can upload binary data infinite_root PHP 9 08-27-2004 07:03 PM
Filling a datagrid with BLOB data vinny MS Technologies ( ASP, VB, C#, .NET ) 2 08-19-2004 12:06 AM
dotnet Data Access reader vs adapter, and MySQL APIs vs SQL2k sde MS Technologies ( ASP, VB, C#, .NET ) 3 12-04-2003 07:45 AM
Would this data be of use too you? SiteTutor Lounge 3 08-02-2002 06:58 AM


All times are GMT -8. The time now is 04:31 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting