-2

I have been trying to change the images in the WampServer Index.php File... When I looked at the Index.php File I saw something Interesting. The File its self was containing the Image in the RAW format. Latter in the Code the PHP Script Calls the Image using the URL like http://localhost/index.php?img=pngFolder called a Image file stored RAW in the PHP file as a png.

Here is a link to a website that has the index.php code... Link

I would Like to know how to replicate this same process to work for other images. Granted the File will be larger but its a Price to pay for what I am doing for a project. The Reason I want some help with this is so I can do it correctly. I have Tried 2 times already. I managed to get it to call one image correctly but not some of the others. I'm not sure if the image is just a different encoding or what..... Any Help would be Appreciated.

Josh J
  • 6,813
  • 3
  • 25
  • 47
Noah
  • 859
  • 7
  • 17
  • Please post any relevant code here so it is preserved for future visitors to SO. – Jay Blanchard Jan 12 '16 at 14:12
  • 1
    Where is your attempt ? Can you share that you are trying? – Marcos Pérez Gude Jan 12 '16 at 14:12
  • How specifically is your attempt failing? – David Jan 12 '16 at 14:13
  • Instead of putting the RAW code in the php file, why don't you store the images in a folder and then serve them by the php file with the right content type header? (for example `image/jpg`) – Marcos Pérez Gude Jan 12 '16 at 14:14
  • 1
    Note that this is seldom a good practice. The image size increases with the encoding, they can't be cached, etc. – Gerald Schneider Jan 12 '16 at 14:14
  • @MarcosPérezGude I'll have to Upload it Tomorrow or Tonight (I do not have Internet at home Just Cellular. So I'll have to upload it when I get to school.) the Part I am having a problem with is basically the encoding or the code of the image – Noah Jan 12 '16 at 16:04
  • I repeat, the same as @GeraldSchneider, that practice is not a good idea in most cases. I don't know why you need to make it by this mode, instead of that I purpose to you. – Marcos Pérez Gude Jan 12 '16 at 16:09
  • @MarcosPérezGude Yes I have done that before and I would not mind doing that but My plan is to do some work to basically Store the Images RAW encoding in a MySQL database for a profile. But if this method is not reliable or is not recommended then I'll probably use another method like use FTP or use the PHP upload option. The server runs on windows for now the. I'll change it OS if I need to Linux. – Noah Jan 12 '16 at 16:10
  • You are attempting to store the images in a MySQL database? If you are making that for performance, you are wrong. Is totally the opposite. You lose performance with that technique. You are able to store images in binary (blob in mysql) and then decode with php, but why not upload into a folder that requires less resources in server, and then the performance will be better in server and in client? You can serve the image by a php file too. And your database doesn't have tons of MB of images. Databases arent for store binary objects, almost not thinked to this. However you can if you want. – Marcos Pérez Gude Jan 12 '16 at 16:15
  • @MarcosPérezGude I under stand that all it is just for my testing project. I like to learn and Mess with code. I'm just seeing and testing the limitations of PHP, MySQL and the Client Machine and even the server that has to process the PHP Script...... Again I'm just testing and Playing around with the Limitations. I know in real world situations to not use something such as me method. If you look at something like Wordpress it uses other methods for uploading files within the upload limits, etc.... – Noah Jan 12 '16 at 16:22
  • Ah Ok! If it's for testing and learning purposes, go forward with that! No problem. I suggest to you to store in mysql with blob instead of base64 as other people suggest. Search about **"PHP store images mysql blob"** and you'll obtain thousands of articles and tutorials. – Marcos Pérez Gude Jan 12 '16 at 16:32
  • @MarcosPérezGude Ok thanks. You've been a help! – Noah Jan 12 '16 at 16:46
  • You are welcome.See that for example http://stackoverflow.com/questions/7052655/insert-blobs-in-mysql-databases-with-php – Marcos Pérez Gude Jan 12 '16 at 16:47

1 Answers1

1

They are using BASE64 to encode the images into text. You can google for a base64 encoder that will convert your images to text. You can then put the text directly in an <img src="..base64 text.." />

Here's one..

https://www.base64-image.de/

As far as getting the image from the url index.php?img=pngfolder..

You could put this at the top of the file

if(isset($_GET['img'])){
    echo "...base64 string.."; exit;
}

Then you can use the index url as the src for your image and it will simply retrieve the base64 image

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116