473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

reading a dynamic image to a string

This is how I put a jpg into a string.

---------------------------------
$File1 = "pic1.jpg";

// open for read/binary-safe
$objFH = fopen( $File1, "rb" );
$strBuffer1 = fread( $objFH, filesize( $File1 ) );
fclose( $objFH );
----------------------------------

Which is fine when pic1.jpg exists, but pic1.jpg is created live by
calling pic1.php which outputs a jpg, pic1.jpg.

If I try fopen( "pic1.php", "rb" ) it will give me the php file, I want
it to open the image file, preferably without writing it to disk.

Herc

Jul 17 '05 #1
6 1643
I'm not sure if this is what you mean, but if you want to prevent the
fopen call when pic1.jpg doesn't exist, just use file_exists():

$File1 = "pic1.jpg";

// open for read/binary-safe
if (file_exists($File1))
{
$objFH = fopen( $File1, "rb" );
$strBuffer1 = fread( $objFH, filesize( $File1 ) );
fclose( $objFH );
}

--
http://www.phpforums.nl

Jul 17 '05 #2
thanks but that's not what I was after, there's no pic1.jpg on the
disk, its the output from pic1.php.

like this
<img src="button.php?text=home">

will put an image on your page, a button graphic with the word 'home',
but there's no button.jpg anywhere on the server.

Is is possible to read the file button.jpg without writing it to disk
1st, you have to invoke PHP to parse button.php?

Herc

Jul 17 '05 #3
Okay, I get what you mean now.
Isn't it an option to write the imagedata to a session-var and then
read that sessionvar from the script including the button-creation
script?
That way you don't have to worry about the imagefile being overwritten
each time a user opens the page, since each user has his own session.

Peter.

--
http://www.phpforums.nl

Jul 17 '05 #4
Do $data = @file_get_contents("http://<server>/button.php?text=home").

Naturally, you'd need to resolve the relative URL first.

Jul 17 '05 #5
thanks that works!

Herc

Jul 17 '05 #6
button.php uses this

header("Content-type: image/jpeg");

and returns as a binary file instead of html. so button.jpg can't be
overwritten its just like fetching HTML but you fetch a graphic
instead. it will run the same routine again and again for the same
graphic though.

Herc

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: K | last post by:
I have found a script online that I want to use (I am new to PHP). It creates dynamic images based on the text that you pass it. However, no matter how I try, I can't get anything other than a...
7
by: duncan.lovett | last post by:
I want to generate dynamic heading images, but I won't be able to use the GD Library, ImageMagick or any other plug-in to generate an image on the fly due to hosting restrictions. I have seen,...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
7
by: dino d. | last post by:
Hi- I want to create a dynamic image with areas so that when the user clicks different areas, the user jumps to those pages. The problem is, I can't seem to figure out how to do this efficiently....
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.