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




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




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Access The BLOB Data Type
How should I access the BLOB data type using PHP from a MYSQL database ?

Convert Binary To String ?
what's the correct function for that cause i can't seem to find it no where !

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.

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?

Convert Byte To Binary
I'm receiving 2 bytes of data from a socket connection.
They are shown as 2 unknown characters.

What I need to do is view their binary representation.

I've been playing around with unpack, but can't seem to get anywhere. Google hasn't helped a bit.

Like, if I just had "e" how could I convert that to "01100101"?

Convert Signed Hex Value To Big-endian Binary?
Anyone know how to convert this java code to php?

// Take the signature passed, a signed hexadecimal value and
// and convert to a byte array in 2's compliment, big-endian.
// We wrap in a try-catch in case the signature is not a signed
// hexadecimal number
byte[] barray = new BigInteger(signature,16).toByteArray();

Converting A Hex String To A Binary String?
I have a situation where I have an 8-byte string which is represented as 16 hex digits. How do I convert a 16 hex digit string to an 8-byte binary string?

I know I can use bin2hex to go from a binary string to a hex string (very useful)but is there a way to go the other direction? Right now I have a solution, which is to use a loop to go through the hex string one byte at a time, but that doesn't seem like a good way to do it. It seems like I should be able to use the pack() command, but I can't get it to work.

Blob Data - Timeout Issue
Hello,

I have success when uploading a binary file to a mysql "blob" type when a file is not larger than 2.5MB. When uploading a file >2.5MB, I get an error of MySql server has gone away or cannot allocate file and I get "Couldn't Add File to Database" .
I've read the manual on the error, but having checked all the settings i.e. max_allowed_packet=16M, php.ini settings of upload_max_filesize=16M, post_max_size=16M, max_execution_time=3600 and also httpd.conf timeout= 3600 and the error still persists. Is it mysql, php, apache or the script?

HTML:

<form enctype="multipart/form-data" name="frmUploadFile" action="grabfile.php" method="post">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="16000000">

The script: grabfile.php

<?
$dbServer = "localhost";
$dbDatabase = "";
$dbUser = "";
$dbPass = "";

$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);

$sConn = mysql_connect($dbServer, $dbUser, $dbPass)
or die("Couldn't connect to database server");

$dConn = mysql_select_db($dbDatabase, $sConn)
or die("Couldn't connect to database $dbDatabase");

$dbQuery = "INSERT INTO myBlobs VALUES ";
$dbQuery .= "(0, '$strDesc', '$fileContent', '$fileUpload_type')";

mysql_query($dbQuery) or die("Couldn't add file to database");

echo "<h4>Upload of $fileUpload_name is complete.</h4>";
echo "The details of the uploaded file are shown below:<br><br>";
echo "<b>File name:</b> $fileUpload_name <br>";
echo "<b>File type:</b> $fileUpload_type <br>";
echo "<b>File size:</b> $fileUpload_size <br>";

?>

Any suggestions?

BLOB Data As Src For Thumbnail Creation?
I have images stored on my MySql database as Binary "BLOB" filetypes. I want to make thumbnails of these files to display. I know how to create thumbnails using paths and image names of .jpg files. But I do not know how to use Binary"BLOB" image data to create them.

Do I have to encode the data in a certain format for the getimagesize(), ImageCreateFromjpeg() and imagejpeg() functions to work? Or does this have something to do with specifying a MIME type? I don't know how to get the functions to read the BLOBs.

How Do I Get Image Data Into A Blob Field
I am trying to get image data into a mysql field (like a simple jpg). Does anyone have a quick tips on how to submit an image (through an html form) process via php and insert into a mysql blob field?

String Representation Of Hex To Binary?
I'm trying to verify some data which is posted to a php script from an external server. One of the posted fields is a signed hex number, but its obviously a string as part of the $_POST vars. I need to convert this value to a binary number so that it can be encrypted and then verified. Code:

Removing Trailing 0's From A Binary String
I need to trim off trailing 0x00's from a binary string. Does anyone know how?

How Do You Make A String Of Binary Numbers From An Array
I have an array of numbers, and I need to turn it into a single binary
string. How do I do that?

Php, MySQL, And Binary Data
I'm trying to upload binary data and store it in mySQL as a mediumblob. Since there's always the possibility of quotes (along with any other character) within the binary stream, I assume I need to do something along the lines of AddSlashes to ensure that the sql request won't fail. The trouble is I'm finding that StripSlashes is blowing away the string when I retrieve it. I've tried rolling my own encoding, but ereg_replace("'", "'", $string) is truncating my data, apparantly at the first null character it hits.

So: what's a solution for safely getting binary data into mysql via php?

Sending Binary Data Via UDP
I'm trying to send a packet of binary data to a UDP server. If I send
a text string, it works fine. If I attempt to send binary data, it
sends a UDP packet with 0 bytes of data (just the headers). I can see
this because I'm running Ethereal and watching the packets.

I'm defining the packets as shown below:

$text_msg = "Hello, world
";
$binary_msg = chr(0x01).chr(0x02).chr(0x03).chr(0x00).chr(0xA0);
$binary_msg_size = 5;

Initially, I tried using
$fp = fsockopen("udp://" . $server,$port,$errno,$errstr)
and
fwrite($fp,$binary_msg,$binary_msg_size)

Since this didn't work, I then tried
$sock = socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
and
socket_sendto($sock,$binary_msg,$binary_msg_size,0 ,$server,$port);

For both methods, sending $text_msg worked, but sending $binary_msg
resulted in a UDP packet with 0 data bytes being sent.

I've found examples of sending binary data, but they used TCP, and
I've found examples of sending UDP, but they send text strings.

Anyone have experience with sending binary data to a UDP server?

Size Of Binary String On Multi-byte System?
if you are given binary data in a string (such as from a call to
fread), you can call the strlen function on this string to get its size:

$buffer = fread($file, 100000);
if (strlen($buffer) < 100000)
{
echo "read less than 100000 bytes";
}
etc

now, the problem is, on systems where you have the mbstring extension
turned on, and are using function substitution to replace strlen with
mb_strlen, you are pretty much guaranteed to get a WRONG value back from
strlen, since it will find some multi-byte lead characters in that binary
file eventually.

so the question is:

are there any other methods to find the length of a string besides strlen?
the only way i can see to not screw myself right now is to not use function
substitution.

Receiving Binary Data Using Sockets
I'm using sockets to communicate with an external device. This device sends out 5 bytes that I wish to receive and analyze. The problem I have is that the response I get seem to be converted into unicode(?)

Sending Binary Data With PHP Sockets
Is there any mean to send binary data with PHP using sockets? What I find so far is only sending and receiving Strings. I would be grateful if you could help me. Thanks.

Emailing Binary Data Question
I'm trying to create an 'email this picture' form using a php email class ("phpmailer"), & wish to embed the image in the body of the email, as opposed to attaching the image file.

The images are binary files referenced by fields in a mysql table, and are displayed using a function call that produces code without a .jpg extension - e.g. "<img src=img.php?f(3e7b67c7dd510)+w(45%)+h(45%)>" (I've used this script).

For the life of me I can't work out how to embed such an image into an email, & am thinking that maybe a workaround would be to rename the image with a simple .jpg title, save it to a temp directory, & delete after sending each email. What I'd like to know is:is this the best way to go forward?if so, how can it be done?

Display Binary Data From A Function
I am trying to retrieve binary data (a JPEG or GIF for this example) from a function and display the data on a seperate page. The function is held in a file called getdata2.php and looks like this. PHP Code:

Image Manipulation With Raw Binary Data
Is this possible to use straight up binary picture data pulled from a MySQL database in substitute for the "real" image that this funciton below wants?

$original = ImageCreateFromGif($img_path);
$original_width = ImageSX($original);
$original_height = ImageSY($original);
$thumb_width = 40;
$thumb_height = 40;
$thumbnail = ImageCreate($thumb_width, $thumb_height);

ImageCopyResized ($thumbnail, $original, 0, 0, 0, 0, $thumb_width, $thumb_height, $original_width, $original_height);

Send Binary Data To Socket
Quick & simple question:
I have to send the next data to a socket in order to make a popup visible on
a windows machine..

TITLE Title of popup [enter]
TEXT Text in popup [enter]
POPUP [enter]

<?
$s=socket_raw_connect($host,$port,15,'TITLE Test
TEXT Text in
popup
POPUP
');

function socket_raw_connect ($server, $port, $timeout,$request) {
if (!is_numeric($port) or !is_numeric($timeout)) {return false;}
$socket = fsockopen($server, $port, $errno, $errstr, $timeout);
if(!$socket) { echo "Opening socket error"; exit(); }

sleep(10); #Wait for program... bug :-)
$put=fputs($socket, $request);
sleep(10);
fclose($socket);
}
?>

Now, I have tried the whole scala of

x0a etc.. for
but it
doesn't seem to work..

Getting And Using Binary Image Data From ImageMagick
I am trying to use ImageMagick to create thumbnails on the fly - without
having to save the image to a file.

I have gotten it to work by using passthru($cmd, $retval), but I want to
use something else that will give me the complete output returned as a
string that I can convert to a GD lib image resource so I can verify the
operation worked before sending the Content-type header for the image.

This works:
---------------------------------------------------------
// $photo = path to image file
$cmd = "convert.exe -size 250x250 "$photo"" .
' -resize 125x125' .
' -strip' .
' -unsharp 0.2x0.6+1.0' .
' -quality 87 JPG:-'

header("Content-type: image/jpeg");
passthru($cmd, $retval);
---------------------------------------------------------

Using this, the resized image is displayed in my browser.

However, I would rather get the binary output from ImageMagick into a
variable and then test retval (or use some other method) to determine if
the operation was successful.

I've tried shell_exec ...
$output = shell_exec($cmd);
.... but the data in $output appears truncated (ÿØÿÃ*�JFIF�,,��ÿÛ�C�
- is all there is). ?

Updating Images (Binary Data)
I have a page that I use for users on my site to upload an image (displayed on their personal page).

I am trying to figure out how I can update/replace the image in the database so that they can change their image.  Can binary data be updated? Here's the code for my upload script: Code:

Convert A String To A Numeric String ?
Is there a way to convert a string to a numeric string ?

Data Type Change Without Loosing Data
I have a problem in mysql. I stored a date in  08/14/2006 format and choose a datatype longtext now i want to store date in 2006-08-14 form is it possible to do it without loosing data in db when i convert datatype longtext to date the data lost. Any solution?

Reading Data From A Simple Binary File
I've read some discussions, searched Google, tried pack, unpack,
bin2hex, explode, implode, and I just can't figure out how to convert
this data. I am trying to read a file with the following format (two
examples).

41 6D 74 72 61 6B 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 75 05 1A 00

41 6D 74 72 61 6B 20 4F 6E 6C 69 6E 65 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 8F 05 2B 00

The first 28 bytes are a 00 terminated character string (in this case
"Amtrak" and "Amtrak online")
Next are the location (offset) of an entry in another file (2 bytes),
followed by that entry's size in the file (the next 2 bytes). The above
examples are key entries in an index file pointing to variable sized
entries in a data file.

I am using fread to put each field into a string variable (28 bytes, 2
bytes, and 2 bytes). The binary values are "Little Endian" (right?). In
other words 75 05 is really x0575 and 1A 00 is really x001A. I am having
the most trouble with these (I've already used bin2hex, but I don't know
how to convert the little endian to decimal.)

1. I want to strip the 00's from the string.

2. I want to convert the location (offset) into an integer variable.

3. I want to convert the size into an integer variable.

I am going to use location and size to fseek and fread the entries in
the data file into another string.

My actual goal is to transfer this data (the string and it's associated,
variable sized text field) into a MySQL database.

My guess is (was) that this is easy, but I just can't figure it out.

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);

Convert String To An Int
how can i convert a string into an integer? say i have a form that submited 10. i want that converted to integer.

Convert To String
How do you convert a real value to a string in PHP?

Problem With String Type
I try to detect the encoding type of a string $myString which comes
from a html file.

$myString = file_get_contents($myFileName);

Firstly : I tried to get the charset in <meta charset="iso-8859-1">.
But I've the following problem. Internet Explorer write ISO-8859-1 even
if we have save it in Unicode format (UTF-16).

Secondly : Use a algorithm which detect encoding format w3 has proposed this one which detect utf-8 format ...

Convert String To Date
I'am trying to manipulate csv file using PHP, but my problem is that, one field there is date DD/DD/YYYY. My question is, how can I convert that text to date? So that I can insert it to the mysql database correctly.

Convert A Variable Name To A String
How do I convert a variable name posted from a form element into a string?I.E:
--------------------------------------------------------------------------
From:
$1011 = "10"; // Product ID and the value of the Quantity
to:
$product_id = "1011";
$quantity = "10";
--------------------------------------------------------------------------
Unfortunately my client has already had the site built entirely in Flash, so there is not much I can do about getting the form changed.

Convert URL String To Numbers
I do&#769;nt know what keyword to search for this on the forum, but I am asking anywa&#803;y Say I have a url like http://www.mydomain.com/index.php?id=15

Now how do I make this URL to be appreared to my viewer like http://www.mydomain.com/index.php?id=726183182768 Which is the same with id=15 The reason I want to do this is for security purpose, I don't want to expose the real record id to my viewer.

Convert GMT String To EST Output
I have a string and time conversion question: How can I go about converting a string in the GMT format:

Fri, 04 May 2007 19:57:14 GMT to an EST format such as Fri, 04 May 2007 2:57pm EST
So is there a way I can always extract the portion 19:57:14 GMT  --->  x:xxam EST

Convert STRING Charset
I have a MySQL database, which stores data in UTF-8 Unicode format. I have a webpage which has a form where I enter data to store the information and the CHARSET for that page is ISO-8859-1 (latin1).

When I fetch data from my database on a page that has the CHARSET ISO-8859-1 the output is great!
But when I now from another page has UTF-8 Unicode CHARSET set and fetch data from the database, some of the characters are messed up (like the Swedish Å Ä Ö characters).

My question follows:
Can I with PHP, fetch text from my database into a STRING and then "convert" from ISO-8859-1 to UTF-8 Unicode before outputting it to the page which has CHARSET UTF-8 Unicode? OR Do I have to "loop" through and replace "bad/wrong" characters into UTF-8 Unicode, and if so, HOW?

Convert String To Integer
array_multisort($mobile, SORT_ASC, $text_array);

How to convert the string value to integer value .

The sort is the order as string value..

4563423
45435462434
623765457657
4568678643557

But I want the numbers from ascending order of integer value.

Convert From Array To String
i am having a small problem with my code i want to convert from array to String. i tried using the (string) casting but it doesnot work?

Getting File Type From A String Into Anchor
I'm pulling out links from a database, some of them are images, some are movies, some are URLs and some are just download files. I need a way to differentiate each of the to be printed in the anchor tag this is what I'm doing: Code:

Trying To Convert String To Decimal Equivalent
I am trying to convert a string of any given length (can include special characters such as :,/,-,.,etc...) into its decimal equivalent. I've tried all of the php functions I can find, but they all seem to deal with hex or binary.

For example:
h == 104 (it is ok if the function adds the html enties on &#104;)

(here is a table of the decimal equivalents http://www.neurophys.wisc.edu/www/comp/docs/ascii.html)

I've tried:
HexDec()
bin2hex()
BinDex()
etc....

Can anyone tell me how to convert this value?

Convert A String To Unicode/UTF8
how to convert a ascii string to Unicode/UTF8 format?

How Do You Convert A TCL List Into A String That PHP Can Read?
I have a TCL proc that needs to convert what might be a list into a
string to read

consider this:

[set string [PROPER_CASE {hello world}]]; # OUTPUTS Hello World which
is fine for PHP

[set string [PROPER_CASE {-hello world}]]; # OUTPUT {{-Hello}}
World, which PHP will print literally as {{-Hello}} World, instead of
-Hello World

Is there an easy way for TCL to brute-force a list into a
strictly-string-only format to prevent this potentially ugly display
from being displayed by PHP/etc.?

Convert Javasript Variable To Php String
How can I convert 'num' in the following to a php variable called $num? PHP Code:

Convert To Integer From String Format!!!
i have here a function that gets the # of linkdomain in yahoo using CURL then use a preg_match pattern to get the actual value ok the problem is the return value is a string format that i cant convert to in, i have tried using the (int) and intval($string) thing but they only make the value become zero whats the problem? Code:

Convert Two-Dimensional Array To String
I'm trying to convert a two-dimensional array to a string that I can put in a database. It needs to be searchable so the serialize() function will not work. I found a script at php.net that will implode a multi-dimensional array and it works fine. The script is: Code:

Convert Unknown String Format To UTF-8
I have a problem with converting strings to UTF-8. Iconv an get encoding function are not working properly. Code:

String Functionality - Convert (.com, Net, And .org.) Into Href Link
I want to have a function in string when a portion of it sees .com, net, and .org. Convert that word contain (.com, net, and .org.) into href link.For example this:FeedPHP.com is going to be the largest repository of feeds from PHP.net and related news sources. This one stop news source parses feeds from thousands other php website and displays the titles. As we know, MySQL.com, PostgreSQL.org, AJAX are also relevant to PHP.net, so FeedPHP.com collects feeds from those sources as well.will convert to:FeedPHP.com  is going to be the largest repository of feeds from PHP.net and related news sources. This one stop news source parses feeds fromthousands other php website and displays the titles. As we know, MySQL.com , PostgreSQL.org , AJAX are also relevant to PHP.net  , so FeedPHP.com  collects feeds from those sources as well.

Convert A Long Sentence Into Words/string
how to convert a sentence into strings Eg. "I am just a beginner in this PHP" into new lines as follows:

I
am
just
a
beginner
in
this
PHP

Convert String To Integer - Not Starting With A Number
I can't get PHP to convert a string to an integer (or pull the numbers OUT of a string) if it doesn't start with a number, which is an issue.

Basically, i'm trying to pull the integers only out of various model numbers for pieces of equipment our store is selling - examples would be something like S820D or MS1798. I only need the 820 or the 1798 from these strings, but PHP doesn't want to play nice with either:

$product_model = "S820D";
$var = intval($product_model);
or
$var = (int) $product_model;


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