mheinjr Posted March 28, 2006 Share Posted March 28, 2006 [b]1st thing:[/b]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[b]EG:[/b] magick.php/picture.jpgnow 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--][b]2nd thing:[/b]I want to make the .php LOOK like a directory and not a .php file[b]Don't WANT:[/b] magick.php/picture.jpg[b]I WANT:[/b] magick/picture.jpgI 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. Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/ Share on other sites More sharing options...
wisewood Posted March 28, 2006 Share Posted March 28, 2006 [code]<?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>"?>[/code]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... Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21505 Share on other sites More sharing options...
mheinjr Posted March 28, 2006 Author Share Posted March 28, 2006 I put that code into a php named test3.php[b]When I enter this into the address bar http://<my sevrer>/test3.php/picture.jpg I get:[/b][!--coloro:#3366FF--][span style=\"color:#3366FF\"][!--/coloro--]The full URL is: http://<my server>/test3.php/picture.jpgThe image name is: picture.jpg[!--colorc--][/span][!--/colorc--][b]but when I make a html file with this in it: <img src="http://<my server>/test3.php/picture.jpg"> I get: [/b][!--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 Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21534 Share on other sites More sharing options...
redbullmarky Posted March 28, 2006 Share Posted March 28, 2006 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.jpg2, send the headers3, 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.cheersMark Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21547 Share on other sites More sharing options...
mheinjr Posted March 28, 2006 Author Share Posted March 28, 2006 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 Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21639 Share on other sites More sharing options...
redbullmarky Posted March 28, 2006 Share Posted March 28, 2006 [!--quoteo(post=359339:date=Mar 28 2006, 05:27 PM:name=mark383)--][div class=\'quotetop\']QUOTE(mark383 @ Mar 28 2006, 05:27 PM) [snapback]359339[/snapback][/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:[code]<?php$file = all the stuff from a previous post to get the filename. header("Content-type: image/jpeg");imagejpeg($file);?>[/code]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] Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21644 Share on other sites More sharing options...
mheinjr Posted March 28, 2006 Author Share Posted March 28, 2006 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 fileI 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:[b] <img src="http://www.myserver.com/images/[!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]test2.php[!--colorc--][/span][!--/colorc--]/tattoo-scar.jpg>[/b]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[b]INSIDE test2.php[/b] 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--]<?phpheader("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--] [b]$file = "public_html/images/tattoo-scar.jpg";[/b] imagejpeg($file); echo $file;[/quote]and when I do that [b]http://www.myserver.com/images/test2.php/mypicture.jpg[/b] 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: [b]public_html/images/tattoo-scar.jpg[/b] as I tell it to?How come that is renaming $file to the Request_URL? Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21747 Share on other sites More sharing options...
mainewoods Posted March 29, 2006 Share Posted March 29, 2006 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.com/itsowndirectory/picture.jpg">--tell me if this works Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21785 Share on other sites More sharing options...
mheinjr Posted March 29, 2006 Author Share Posted March 29, 2006 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[b]What I did was:[/b][color=#3366FF]1. added: header("Content-type: image/jpeg"); to my magick.php2. added: AddType application/x-httpd-php .jpg to .htaccess...3. renamed magick.php to magick.jpgI went to [a href=\"http://www.myserver.com/magick.jpg\" target=\"_blank\"]http://www.myserver.com/magick.jpg[/a] and it [b]echo'd[/b] the address in the address barI used <img src="http://www.myserver.com/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. Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21798 Share on other sites More sharing options...
mheinjr Posted March 29, 2006 Author Share Posted March 29, 2006 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--]<?phpheader("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 [b]when I add this to the end of my .php file it doesn't work "it is blank"[/b], 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.[b]EDIT:[/b] 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; :) Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21831 Share on other sites More sharing options...
mheinjr Posted March 29, 2006 Author Share Posted March 29, 2006 [b]GUYS, you are awesome.. thanks a bunch for your help.[/b][!--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--][u]mainewoods[/u], 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--][b]EG: magick.php/picture.jpgwould now be used as: magick/picture.jpg[/b]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 Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21837 Share on other sites More sharing options...
mheinjr Posted March 29, 2006 Author Share Posted March 29, 2006 OK guys, thanks a bunch I think I fixed it how I want itI added [b]Options +Multiviews[/b] into the .htaccess file! Now I can use it as a directory.Thanks, Mark Quote Link to comment https://forums.phpfreaks.com/topic/5984-2-questions-using-a-jpg-to-disguise-a-php/#findComment-21919 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.