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

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2005, 09:26 AM   #1 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 122
metazai is on a distinguished road
Detecting binary image types with PHP . . possible?

Hey - I'm playing around with storing image files as binary data in my MySQL database, and pulling them down using the following code:

PHP Code:
if($id) {  
    
$conn mysql_connect('sqladdress''username''password') or die ("Problem connecting to the database" mysql_error() ); 
    
$rs mysql_select_db("databasename"$conn); 
    
$query "select imagebinary,filetype from show_info where id=$id";
    
$result mysql_query($query);

    
$data mysql_result($result,0,"imagebinary");
    
$type mysql_result($result,0,"filetype");

    
Header"Content-type: $type");
    echo 
$data;
}; 
which is saved as filetype.php, and accessed with:

Code:
<img src="filetype.php?id=1">
This works fine, but I'm setting this up for some endusers who don't know a gif from a jpg from a hole in the ground -- is there a way to use PHP to detect the file time for the header information directly from the binary code? Anybody heard of such a thing?
metazai is offline   Reply With Quote
Old 02-04-2005, 10:16 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
i dont understand. you already have the file type there. do you mean when you initially insert the file into the database?

if you do mean when you initially insert the file, check out: getimagesize()

that returns the dimensions along with the file type of the image.
__________________
Mike
sde is offline   Reply With Quote
Old 02-04-2005, 10:49 AM   #3 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 122
metazai is on a distinguished road
No, actually, I mean when you're pulling it down, but it would work either way. I wasn't aware of that command, and I think it will do what I want on either side, so let me play with that now. Thanks (again)!
metazai is offline   Reply With Quote
Old 02-04-2005, 11:04 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
hey meta, i went to a php meetup at the block last night. it was pretty cool. you should check out the next one.
__________________
Mike
sde is offline   Reply With Quote
Old 02-04-2005, 11:21 AM   #5 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 122
metazai is on a distinguished road
Maybe I will . . . do they have a website with info?
metazai is offline   Reply With Quote
Old 02-04-2005, 11:39 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
http://php.meetup.com/41/ .. we just registered http://ocphp.com last night so it's not used yet.
__________________
Mike
sde is offline   Reply With Quote
Old 02-16-2005, 10:35 AM   #7 (permalink)
jpwjpw
Registered User
 
Join Date: Feb 2005
Posts: 1
jpwjpw is on a distinguished road
try this:

$filetype = explode("/",$_FILES['filename']['type']);

This returns the file format like 'image/jpeg' in an array split by the /(i.e.

$filetype[0] = image
$filetype[1] = jpeg
jpwjpw 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 vs .NET Redline Lounge 1 11-24-2004 06:10 AM
php script that can upload binary data infinite_root PHP 9 08-27-2004 06:03 PM
Php image. Nasimov PHP 1 03-11-2004 05:28 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM


All times are GMT -8. The time now is 02:00 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





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