Jump to content


Photo

2 questions... using a .jpg to disguise a .php


  • Please log in to reply
11 replies to this topic

#1 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 28 March 2006 - 03:29 AM

1st thing:

OK what I have here is a file called magick.php! I am using this file to get php code but disguise it with a .jpg

EG: magick.php/picture.jpg

now when I go to that link what it really does is opens magick.php and does whatever I have the code says to do in it. Right now the code works fine for what I am doing with it.

I want to add to it though.

I want it to be able to actually return A image no matter what I specify when I do a <img src="magick.php/picture.jpg"> but I do not know how to do this.

[!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]I cannot use Header because that will ask if you want to download the file[!--colorc--][/span][!--/colorc--]

2nd thing:

I want to make the .php LOOK like a directory and not a .php file

Don't WANT: magick.php/picture.jpg

I WANT: magick/picture.jpg

I read this somewhere but do not know how to do it:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
if you want to remove the ugly .php part of your URL, but you don't want to redefine the default type for every document affected by that .htaccess file, you can do so by removing the AddType directive and replacing it with Option Multiviews. This is a generally preferable method, since it applies to every kind of file, and doesn't require you to sacrifice informative file extensions on your server.
[/quote]

Can someone help me out please? I am new to php, and have been doing alot of reading, and putting together some code.

#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 28 March 2006 - 10:28 AM

<?php    
function selfURL() 
    {
    $s = empty($_SERVER["HTTPS"]) ? ''
    : ($_SERVER["HTTPS"] == "on") ? "s"
    : "";
    $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
    $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
    : (":".$_SERVER["SERVER_PORT"]);
    return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
    function strleft($s1, $s2) {
    return substr($s1, 0, strpos($s1, $s2));
    }     
    $this_url = selfURL();
    echo "<b>The full URL is:</b> $this_url<br><br>";
    
    $slash_pos = strrpos($this_url, "/");
    $pos = $slash_pos + 1;
    $image = stripslashes(substr($this_url, $pos));
    echo "<b>The image name is:</b> $image<br><br>"
?>

if you then do <img src="<?=$image?>"> you will be able to use the image variable snatched from the end of your URL as your image.

I think this does what you were after...

wisewood: proven fact, I am both wise, and wooden.

#3 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 28 March 2006 - 11:50 AM

I put that code into a php named test3.php

When I enter this into the address bar http://<my sevrer>/test3.php/picture.jpg I get:

[!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]The full URL is: http://<my server>/test3.php/picture.jpg

The image name is: picture.jpg[!--colorc--][/span][!--/colorc--]

but when I make a html file with this in it: <img src="http://<my server>/test3.php/picture.jpg"> I get:

[!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]all I get is a broken image.[!--colorc--][/span][!--/colorc--]

Did I do this correctly?

Thanks for your help, Mark

#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 28 March 2006 - 12:40 PM

http://<my server>/test3.php/picture.jpg is returning text (ie, when you type it, you get: The image name is: picture.jpg.

when you put it in <img src="">, the browser expects image data to be returned, not text.

to get an image displayed using this method, your test3.php needs to use the GD library to do the following:

1, imagecreatefromjpeg to open picture.jpg
2, send the headers
3, output the image.

look at 'imagecreatefromjpeg' at [a href=\"http://www.php.net/imagecreatefromjpeg\" target=\"_blank\"]http://www.php.net/imagecreatefromjpeg[/a] to get an idea of what you maybe after.

cheers
Mark
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#5 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 28 March 2006 - 04:27 PM

THank you, I am at work right now and cannot test any codes.

Now that I am briefly looking into this wouldn't I just be able to use Imagejpeg(picture.jpg) to have it send a image when i use: <img src="http://<my server>/test3.php/picture.jpg">

#6 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 28 March 2006 - 04:43 PM

[!--quoteo(post=359339:date=Mar 28 2006, 05:27 PM:name=mark383)--][div class=\'quotetop\']QUOTE(mark383 @ Mar 28 2006, 05:27 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
THank you, I am at work right now and cannot test any codes.

Now that I am briefly looking into this wouldn't I just be able to use Imagejpeg(picture.jpg) to have it send a image when i use: <img src="http://<my server>/test3.php/picture.jpg">
[/quote]

whoops lol i was only playing around with this yesterday too...duh!

Mark, you're spot on. yes you can do it this way. Providing you send the right headers first, you can pretty much have your test3.php as something like:

<?php
$file = all the stuff from a previous post to get the filename. 

header("Content-type: image/jpeg");
imagejpeg($file);
?>

please note that filenames passed to 'imagejpeg' are not URL's (depending on your setting) so you'll need something like: /this/directory/public_html/images/mypicture.jpg instead of [a href=\"http://images/mypicture.jpg\" target=\"_blank\"]http://images/mypicture.jpg[/a]
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#7 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 28 March 2006 - 10:28 PM

OK this is what I tried "making it simple"
I don't want a big thing here :) I just want something simple. SO whenever anyone visits my test.php it will return that file

I have logging code in test.php and I want to display a image along with it.

EG: <img src="test.php/image.jpg"> I want it to LOG the people who VIEW IT "which it DOES" and I ALSO want it to display a image... right now I am using height="0" and width="0" because it doesn';t show anything.


to the code I tried..........

I created a file test.html with this in it: <img src="http://www.myserver.com/images/[!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]test2.php[!--colorc--][/span][!--/colorc--]/tattoo-scar.jpg>
This will display the image I have in the test2.php file despite what I have in that code above... but it doesn't work

INSIDE test2.php is this coding "simple coding... this is so whatever jpg I put it will always return the same one!":
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php

header("Content-type: image/jpeg");
imagejpeg("public_html/images/tattoo-scar.jpg");

?>
[/quote]

still shows broken image!

I have tried Various things... I added this to it:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
$file = "public_html/images/tattoo-scar.jpg";
imagejpeg($file);
echo $file;
[/quote]
and when I do that http://www.myserver.com/images/test2.php/mypicture.jpg I get a broken image + a echo that says: [a href=\"http://www.myserver.com/images/test2.php/mypicture.jpg\" target=\"_blank\"]http://www.myserver.com/images/test2.php/mypicture.jpg[/a].
shouldn't it be echoing: public_html/images/tattoo-scar.jpg as I tell it to?
How come that is renaming $file to the Request_URL?

#8 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 29 March 2006 - 12:48 AM

I think this will work. If you put your picture.jpg in a directory by itself, then you can put an .htaccess file in that directory with this line:
-------------------------------------
AddType application/x-httpd-php .jpg
-------------------------------------------

--Your picture.jpg file will then behave as if it were a .php file!
--You will need to use in the file:
header("Content-type: image/jpeg");

--Then you can just use:
<img src="http://yourcomain.co...y/picture.jpg">

--tell me if this works

#9 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 March 2006 - 01:30 AM

mainewoods, I am not sure "exactly what your saying", I understand making the .jpg file act like a .php file, but I am not quite getting how I would get the picture out of the .jpg file if it is now reading like a .php


What I did was:[color=#3366FF]

1. added: header("Content-type: image/jpeg"); to my magick.php
2. added: AddType application/x-httpd-php .jpg to .htaccess...
3. renamed magick.php to magick.jpg

I went to [a href=\"http://www.myserver.com/magick.jpg\" target=\"_blank\"]http://www.myserver.com/magick.jpg[/a] and it echo'd the address in the address bar

I used <img src="http://www.myserver....om/magick.jpg"> and it returned a broken image "of course"


This did work, and I do like it because now I won't see the .php file ;) however I do want it to display a image while acting as a php file.

#10 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 March 2006 - 04:35 AM

Well I am now able to send a image file when using a .php.... now I just have to incorporate this into my other code


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
header("Content-type: image/jpeg");
readfile("picture.jpg");
?>
[/quote]

I am very tired right now, and going to sleep. I will be working on this tomorrow. What do you guys think about using this way? Is there anything I should add anywhere?

I need to test this some more because when I add this to the end of my .php file it doesn't work "it is blank", but when it is alone like that it works.... also I had a header problem when I tried to add the header part to the top of the .php file.

EDIT: I think I got it.. now I know why it was giving a blank screen when I added it.. Maybe I should take out the exit; :)

#11 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 March 2006 - 05:09 AM

GUYS, you are awesome.. thanks a bunch for your help.[!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]

I got it working though there is 1 more thing I would like to do with this.[!--colorc--][/span][!--/colorc--]

mainewoods, You explained to me how to make the .php be looked at as a .jpg

[!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]How do I make it look at the .php file as a directory?[!--colorc--][/span][!--/colorc--]

EG: magick.php/picture.jpg
would now be used as: magick/picture.jpg


and with the code inside of magick.php I can redirect with the ['PATH_INFO'] "so there is problem with this"

I know I have to edit something in the .htaccess but I don't know what.

Thanks, Mark

#12 mheinjr

mheinjr
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 March 2006 - 12:42 PM

OK guys, thanks a bunch I think I fixed it how I want it


I added Options +Multiviews into the .htaccess file! Now I can use it as a directory.

Thanks, Mark




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users