Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Determining Mime Type Of MySQL Blob?


Is there any PHP function that will allow me to determine the MIME type
of a blob stored in MySQL?

Specifically, if I'm storing an image as a blob in MySQL, is there any
PHP function that can determine whether it's a gif, jpeg, png, etc?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Determining Type Of MySQL Field.
I have a problem of migrating a database from one host to another.
I can't do a dump on the source server. The only access I have is thru
queries. So it looks like I'm going to have to query all the
tables and insert to the destination.

I'm trying to come up with a general solution to this problem which
uses queries to determine the structure of the source db, and create
the tables on the destination, which I've already done using the nice
"show create table" query syntax combined with the PHP
mysql_list_tables() function.

The problem comes with doing the inserts. It looks like I'm going to
have to do a "select * from table" thing and then loop thru the
recordset doing insert after insert.

Q: Do I have to do it that way? Is there a way I can insert all the
records from source to destination more efficiently?

Q: How can I determine the type of value in a field returned from
a query? PHP's is_string returns true on ALL fields regardless of type
used in the database itself. I need to know whether to wrap the values
in quotes or not before I insert them.

I'd like to be able to at least fetch a record and insert the record
without having to process it. I'd like to grab the whole table and
insert it, but haven't a clue how to do this.

Q: Is there some kind of select/fetch that I can do that will give me a
record ready to insert i.e. with commas and quotes?

Getting The MIME Type
I know this is easy if youve just uploaded a file using a form but suppose the file already exists on the server. Is there a function that can be called that takes the filename and returns image/gif or whatever.

MIME-TYPE
I've written a file upload script and want to check the MIME-TYPE of the uploaded files. I've made use of the many posts and come up with the following:

// Check file type from MIME
$allowed_types = array("application/zip",
"application/x-zip",
"applicatoin/x-zip-compressed",
"multipart/x-zip",
"application/x-stuffit",
"application/x-stuffit-compressed",
"application/sit",
"application/x-sit",
"application/sea",
"application/x-sea",
"application/pdf");

if(in_array($file_type, $allowed_types)){
$error = 0;
} else {
$error = 1;
$error_msg .= "<li>The file type you are uploading is not allowed. Compress all files ".
"into ONE (1) archive with StuffIt or WinZip. As an alternative you may ".
"create a PDF file to upload. Consult your software documentation ".
"for more information.
MIME-TYPE not matched.</li>";}

I cannot seem to get a match from any file types in the allowed_types array.

Access The BLOB Data Type
How should I access the BLOB data type using PHP from a MYSQL database ?

Mime Type Question
I have built a form that uploads a file into a directory. Everything works great when i dont validate the form but I have to validate the file type.

The only mime type that i could find for an .xlt file is application/vnd.ms-excel only problem is that i can only upload a .xls file with that mime type. does anybody have any ideas on this? PHP Code:

MIME-TYPE Issue?
I wrote a script that creates an email with 2 attachments. The PDF-attachment is no problem at all. The second one is supposed to be a message, which then can be opened and sent from any mail program. Now I ran into trouble...

The script and everything works fine using Outlook as reciepent. Netscape 6.2. just doesn't seem to recognize the attachment and opens the browser instead of the mail application to show it's content. I'm aware that this might not be a PHP-related problem. PHP Code:

Wrong Mime Type
I tried to reply to another post, and instead of receiving html, my browser came back with a mime type of x-something-php and prompted me to open/save the document. I tried several other links on the page, got similar responses, restarted the browser, tried others... It seems to be working properly now, but I'm currently in possesion of two of devshed's php scripts.

So my question is, what happens when my server does this and database passwords/schema information/obscene comments whatever are exposed to user download? Is this a known issue? What could cause this to happen? I'm using mozilla 0.9.8, but this seems like a server -side issue to me.

Getting File Mime Type
i'm currently doing the attachment for the e-mail system. may i know how to getting the mime type for a attach file selected by a user? if the user select several files with different mime type, how should i handle it?

Who Is Reporting Mime Type?
I have a PHP form that is used to upload files. When a file comes in the _type value indicates text, HTML, or msword--all fine. Things still work if I eliminate the file extensions on the .txt or .html files. Even if I switch them around. But if I remove the .doc from the Word file, I get "application/octet-stream".

Who is reporting this? The client browser? Apache? Is it looking at both the file extension and contents for certain files? Where can I go to find out more information on this? I'm concerned about non-Windows OSes, older browsers, etc. And it would help to know how intelligent the creator of this valuable text field is.

Mime Content Type
I need a function which finds a mime type from string data.php's
mime_content_type function wants only filename to find it.

Mime Type Of A File?
How do I get the mime type of a file on the filesystem?

Print Mime Type
I have the following;

$file = $_GET['filename'];
How can I print on screen, the mine type for this file? Is this easy?

Getting File Mime Type
I have a simple file upload script. but I want to capture and store the files mime type. What is the easiest way to do this?

How To Tell If Mime Type Matches Contents
Before I write the script myself, I'm looking for PHP code that checks
that a link's content type matches it's contents. I need this for my
"broken link" checker script, which fails to spot the "broken" links...

What Is PHP's Mime Type (for Config In IIS)
Can anyone tell me the mime type for PHP files? I'm trying to configure my Windows 2000 server to recognize these file types and I need to know what the mime type is.

Obtaining File Mime-type
Does php have a way of obtaining a file mime type other than for images? I'e, a user may upload an image or a short movie clip, i need to know how to deal with it without having to rely on the file extensions. Script may be installed on a windows machine so file() is out of the question unless windows as an alternative to file().

MnoGoSearch Mime Type Problem
I am doing a Document Management System.
All the uploaded docs are stored in a directory, but the names ae
encrypted
as a long text without any extension.

I use mnoGosearch. To Do search within files and documents,
All mime types should be specified in indexer.conf.

As i have files with encrypted names and no extensions,
They are not indexed by mnoGoSearch.

How to make mnogosearch to detemine the filetype automatically.?

Note: the command "file asajhfjsdiufhjkdfhskjf34287jnjk" gives the
proper file type of it.
eventhough the file name is encryted.

Server Push Using MIME-TYPE...
How to do server push using PHP. We tried with MIME-TYPE:x-MULTIPART-REPLACE but there are some browser Compatibility issues.

MIME Type Validation For File Upload
I am trying to create a validation for my upload script that will only allow: "jpg" and "JPG" files to be uploaded. My script is below; can someone tell me what I am doing wrong and how to fix it - please? Code:

How Can I Convert Ascci Data To Blob (BINARY) String Type?
I want to convert ASCII characters (Stored as TEXT) to MySql Blob data type where the ASCII data will store as BINARY. The data will store like the format below:
 
0x41675a7959ea

Update Mysql Blob With Another Blob Using Php
I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db($dbname, $connection);

$query = "SELECT blobthing
FROM mytable
WHERE id = 1;";

$results = mysql_query ($query, $connection);
$row = (mysql_fetch_assoc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable

$query = "UPDATE mytable
SET blobthing = ".$varblobthing.",
WHERE id = 2;";

mysql_query ($query, $connection);

Displaying Binary Data To Browser And Set Mime Type
I am looking for a link or help on how to set the
mime type in my php script as well as send binary data to the browser
window instead of having it ask me to save the file.

Line Feeds With MIME-Version: 1.0Content-Type:text/html; Charset=iso-8859-1
I added "MIME-Version: 1.0
Content-Type:text/html;
charset=iso-8859-1
" as one of the parameters in the mail( )
function to replace the "Nobody" with a real From: email. That worked.

But if I attempt to add any other terms, such as the sender's name and
location, the MIME parameter above seems to ignore the "
" line feeds
and put the these other terms ahead of the mail message.

Here's my code:

mail("$toaddress", "$subject", "$mailcontent", "MIME-Version:
1.0
Content-Type:text/html; charset=iso-8859-1
From: ".
$youremail
. "
" . $yourname . "
");

The value for $yourname appears ahead of the message [$mailcontent] on
the same line. What I would like it to do is display the message, go
to a new line, then display $yourname.

How Do You Detect Image MIME Type Of An Image In A Directory?
How do you detect an image MIME type if you know of the image in a
directory? For example, I know of:

Code: ( php )

Sending MIME Format Email Without The PEAR Mail Mime Package?
Just wondering if anyone could please help. I would like to use PHP to send
MIME format emails (with binary attachments). But I have to do this without
the use of the mail mime PEAR package? We are on PHP 4.2.2 and we cannot
change that, and we cannot install that PEAR package due to our web hosting....

Accessing BLOB From Mysql Db
hi, i m facing a problem in properly accesing BLOBs from mysql db.
when i display an image stored in the blob field it show some absurd
characters.
i think it is the problem of properly telling browser the mime type of
image of blob field.
that is exactly what my problem is. i do not know how to do that .

Read Blob From Mysql
I do have a mysql database with a BLOB column. What is the proprest way
to read this column ?

Upload Using MySQL Blob
Does anyone have any ideas on how I can upload an image to a MySQL blob?

Write A File From MySQL BLOB
I am storing a BLOB in a MySQL database, and want to know how to write
it out again to a file on the server, in a specified location, in php.

Mysql BLOB Image Resize
Having a small nightmare trying to resize an image that is stored in a blob. Anyone had any experience with this?

I can find is some vague reference to image magic pulling an image from a blob, but that's about it. I DON'T want to have to create a file though to display an image, just pull it from the DB and display it via PHP which is what it currently does.

Word Doc Stored As BLOB In MySQL - Retrieval ?
I've stored a word doc as a LONGBLOB in MySQL. To retrieve the contents of the file, I have a script which creates a temporary file, writes the contents to the file, then auto-redirects the browser to the .doc file; the browser then prompts the user to download the file.

The original .doc, which was uploaded to MySQL and the .doc downloaded from the temp file are the exact same size. However, MS Word won't open the downloaded .doc file, saying that "The document name or path is not valid" Anyone else run into this problem getting Word docs from MySQL?

Mcrypt Blob Upload Problem To MySQL
I have a script in which I am collecting sensitive information via a
form (METHOD=POST) and encrypting the posted variable (format = BLOB)
using mcrypt, then saving it in a MySql table. Using my test
script,everything works fine. Using my production scrypt, everything
works fine for data posted with fewer than 8 characters. If I try to
upload data longer than 8 characters, I get this error message:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'ióU¹
”šC!ÊŒB', &#3901;', &#55614;&#57156;', NULL, &#39150;')' at line 1

The characters ióU¹”šC!ÊŒB' after "near" are the encrypted characters.

There does not seem to be any difference between the test and production
scrypts.

Here is the syntax I am using for saving the record:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "myTable"))
{
$insertSQL = sprintf("INSERT INTO myTable (`Date`, LastName,
FirstName, EcryptedBlob) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['Date'], "text"),
GetSQLValueString($_POST['Lastname'], "text"),
GetSQLValueString($_POST['Firstname'], "text"),
GetSQLValueString($encrypted,"text"));

php v. 5.0.5
MySql v. 4.1.9




MIME Attachments Stored In MySQL
I am parsing a mailbox using the imap functions, pulling out images
attached and putting them into mySQL as BLOB fields. I am having
problems displaying images once they are stored in mySQL, and I think
it may be related to the way I store them.

The following line of code is called after an attachment has been
identified as a GIF attachment:

$rawimage = addslashes(imap_fetchbody($mbox,$m,$part_c));
....where $mbox is the imap link and so forth.

Testing to make sure I am actually pulling info out, a debug line like:

print_r($rawimage);

....displays a bunch of chars that are the image attachment data, and a
line like:

print_r(base64_decode($rawimage));

....displays other, different chars.

Looks good so far - I'm definitely pulling images out as raw data.

So I INSERT the $rawimage into my blob field.

However, on the display page, I send the headers like:
header("Content-type: image/gif");
[get image from database and store it in a var called $image_from_db]
echo $image_from_db;

But I get a broken image...

So I try print_r($image_from_db) on this page (after removing the
header line) and it looks like the chars from the tests before - it's
the same data.

base64_decode($image_from_db) does not make the image display properly,
either, but printing it as such shows all those chars again.

I think I do not understand how base64 encoding and addslashes works
between MIME, php and mySQL. Anybody have any ideas? How should I
format the data when I pull it out of MIME (in terms of base64
decoding), how should I insert it (addslashes is correct?) and how
should I echo it when I pull it out into the displaying php image
generation page?

Quicker/easier/more Secure To Put Pictures In BLOB Fields In Mysql Or In A Directory?
I am researching the best place to put pictures. I have heard form both
sides and I'd like to know why one is better than the other.

Determine Image Information On Image Stored In MySQL BLOB
I store images in my DB as BLOB. When I want to place them in an html
table, I want to determine the width of the image in order to asign the
correct width to the column inside table.
For JPEGs this is working fine, this is my code:

$image = @imagecreatefromstring($r["foto"]);
return @imagesx($image);

where $r["foto"] is the field selected from the db which contains the image.

For GIFs however, its getting really on my nerves !!
I know imagecreatefromstring is not supported in gd2 and I tried several
thinks. None of them worked ! :
-
$temp = tmpfile();
list($width, $height, $type, $attr) = getimagesize($temp);
echo $attr;

gives me :Warning: getimagesize: Unable to open 'Resource id #6' for reading
-
$handle = fopen("/tmp/tmp.dat", "w+");
fwrite($handle, $r["foto"]);
list($width, $height, $type, $attr) = getimagesize($handle);
echo $attr;

gives me : Warning: getimagesize: Unable to open 'Resource id #6' for
reading
-
Doing this with imagecreatefromgif($temp); wont work either !

Can somebody help me out please? by telling me what I'm doing wrong or what
I should do.

Mysql Row Type?
what do I have to set a mysql row to, too be rank them in order when the numbers in the database are &#390;.00' format?

FILE Type For MySQL ?
Is there a FILE type in MySQL??? to store files as a column in a registry of certain table?

MYSQL BOOL TYPE
Im trying to make a setion in my table, true or false, but when i try to make it i get an error. this is what i do and the mistake they say i did. not totaly sure what it means, im using phpmyadmin: SQL query:

ALTER TABLE `user_info` CHANGE `active` `active` BOOL( 5 ) NOT NULL

MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(5) NOT NULL' at line 1

Mysql Data Type Int(10)
i understand that int is 4 bytes, but what does the (10) means?

MySQL Date Type Vs Varchar In Php..?
What are the real advantages and disadvantages behind using varchar length 15 and populating it with a date using date("m/d/Y") opposed to using a date type field.

When you store a date weather it be of Date or Varchar type the date is the same example:01/01/2002. The only difference I can see is how you search or retrieve data. With SELECT staements it seems to be a piece of cake either way. Just a cariousity question becuase I was told if you are going to search using dates you should make it a date field but I really do not see the difference. In some languages using a Date type field can actually come back to huant you later when you need to take the date out and leave it blank or NULL. (Like VB as a front end with access as a backend).

MySQL Field Type For Arrays
What type of field type are arrays stuffed into? VARCHAR ? TEXT?

Dynamically Checking Mysql Row Type
Is it possible to check the types of columns in a mysql resultset so you
don't need to know the type of data returned beforehand?

I'd like to be able to do something like:

if($coltype == "datetime") {
// parse date
}else if ($coltype == "varchar") {
// parse string
}

Best MySQL Field Type For Unix Timestamp?
What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.

Column Data-Type For Storing Serialized Array In MySQL?
I'm really not sure - I used BLOB in the past- but the arrays are only a few kilobytes. But VARHCAR only allows 255 characters at most and the arrays might contain many more characters than that.

Form Type=submit Vs Type=image
I'm wanting to create a form with quite a few SUBMIT buttons that use an image rather then the stock (plain grey) button. Everything works fine when I use this line:

print "<INPUT TYPE="submit" NAME="editaction" VALUE=$id>";

I know which SUBMIT button was pressed by checking the value of $editaction in the receiving page. Now if I replace that line with this one:

print "<INPUT TYPE="image" SRC="icon.gif" NAME="editaction" VALUE=$id>";

I no longer get a value in $editaction. I know about $editaction_x and $editaction_y. Is there no way get to the 'VALUE' (from the VALUE=$id part) as well? Am I missing something? Has the variable name been modified to somthing like $editaction_value?

TIA for any light you can shed.

Determining Kbs
I want to limit people of uploading pictures larger then 256 kbs to my site.
Is it possible for php to recognize that 256 is 256 kbs and not 256 bytes, or is it necessary to write out the numbers in long ( 262144 )
?

Determining Dates
Is there an easy way to determine a future date based on adding a period of time to the current date? More exactly, what I want to do is be able to grab the current date, add 1, 2, 3 days to that date, and then get what that future date will be. Is there an easy way to do this taking into account the different number of days in each month?

Determining Users IP Address
I am writing a Shopping Cart application, and I am currently trying to distinctify my shoppers. I am thinking that the best way for me to do this is to use their ip_address as a component of their customer id.

I don't know how to collect the users ip address using PHP. Does anybody have an answer?

Determining Date/time
I'm retreiving all timestamps by user_id from a database and want to print to screen the week that the date falls in. For example, if I retrieve today's date - 07/24/01, a tuesday, I want to create a link - 07/24/01-07/29/01. (which is Monday - Sunday.)

I want to retrieve all of the timestamps, and loop out the results in the format above (eg. 07/24/01-07/29/01) for every date in the table. The results would look like this:

07/24/01-07/29/01
07/30/01-08/05/01
08/06/01-08/12/01

Sample code that I have is below, I have been going back and forth trying to do this with mysql functions, or doing it with php date() The second query is commented out, but this was another way that I was considering doing this. I can't figure out how to find the week, Monday-Sunday, of any given date. Sample Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved