473,386 Members | 1,705 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,386 software developers and data experts.

Fetching Images via PHP question.

Currently im taking this old piece of code
[PHP]
$fileName = $_GET["file"];
$full = $_GET["full"];
$ext = substr(strrchr($fileName, "."), 1);
$path = "../../../include/images/mini/";
if($full)
$path = "../../../include/images/full/";
else
$path = "../../../include/images/mini/";
if(substr_compare($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"], 0, strlen($_SERVER["SERVER_NAME"]))){
//echo "<br>".$path.$fileName."<br>";
$size = getimagesize($path.$fileName);
$fp = fopen($path.$fileName, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
echo "Unable to find file to open";
// error
}
}else{
return null;
}[/PHP]

And modify it into a funciton that will later be oved into a class. The code above runs perfectly when run by itself or via <img src="Linktothatcode?file">

However when modified into
[PHP] function fetchImage($fileName, $full){
$ext = substr(strrchr($fileName, "."), 1);
$path = "../../../include/images/mini/";
if($full)
$path = "../../../include/images/full/";
else
$path = "../../../include/images/mini/";
if(substr_compare($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"], 0, strlen($_SERVER["SERVER_NAME"]))){
//echo "<br>".$path.$fileName."<br>";
$size = getimagesize($path.$fileName);
$fp = fopen($path.$fileName, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
echo "Unable to find file to open";
// error
}
}else{
return null;
}
}[/PHP]

All that prints to the test document is the called url.
The html of the document shows the <img src="the_ascii_representation_of_the_images_binary ">

Here is the code for the test document.
[PHP]
<?php
include ("../../../include/fetchImage.php");
?>
<img src="<?php fetchImage("e493cac401eab12d8a9ebf989a0efd3ec47e31 601.jpg", 1) ?>" id=\"imgTop\" onmouseover=\"rollover(0)\">[/PHP]

I have assured that all files exist in the directories that im specifying.

What is so different about the 2 different fetching methods that would cause such a differerence in result?
Mar 14 '07 #1
1 1407
Atli
5,058 Expert 4TB
The original code put the image hex-binary-whatever straight into the output, without any <img /> tag, did it not?

If so the problem could be that the browser is expecting only that hex-binary-whatever thing but instead it is getiing html tags, at wich point it stops rendering the hex-binary-whatever and starts rendering text/html.

If you were to create a seperate .php file that would work like the old code, lets call it img.php, and call that in your <img /> tag.

For example.
[HTML]<img src="img.php?path=myimg.jpg" />[/HTML]

Then it would probbly show the image like you want.
Mar 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: C3 | last post by:
Hi everone. I'm trying to write a shell script that fetches a number of images from a map website (www.whereis.com.au). Basically, the page asks you for a street address and then queries the...
0
by: Shujun Huang | last post by:
Hi, I am working on converting Informix database to Postgre. I have one question for fetching records using PostgreSQL. The record I am fetching is a variable size text string. Before fetching...
5
by: randomtalk | last post by:
hi, i want to automate some tasks of gathering photos from web, i tried urllib/urllib2, both ended up without much success (saved gifs with only a border, nothing else).. the code i used was: ...
1
by: JimC | last post by:
I use reflection to get a GIF image that contains a transparency mask (the white background should be transparent) that is part of my C# project build. The problem is that the image's...
2
by: VivekR | last post by:
Hi All Please help me out with this thing in javascript. I am dumb in the world of JS/Html/... I have a url, say www.someurl.com. It has a list of jpgs that can accessed as...
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
5
by: Bhavesh | last post by:
Hello genious people, I m trying to insert a LARGE text from Multiline Textbox into my table of sqlserver2000. I m using vs-2005. Please note that I dont want to store blob data From FILE...
1
by: Bhavesh | last post by:
Hi Bruce, Thanks For Reply. U were right, Needed to pass string , but also need to pass size of Data( instead of 16, passed actual length of data). So that worked for me & didn't get any...
0
by: punitshrivastava | last post by:
Hi to All Senior's, I am working in Asp.net with C#. I am newbie in C#. So i want to fetch mutiple images from database .Database i am using is Sql Server. For this i code: //get the image id...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.