How do I load an image in PHP

I want code that loads an image to a PHP server and then send it to browser.

For example I want sample.php to send an image to browser once it is requested. in other words, I want to create a PHP file that acts like a proxy for an image.

--------------Solutions-------------

why are you doing this? why don't deliver the image directly? if you are trying to display a random image you may as well just redirect to the image using

header("Location: address-of-image");

for delivering the file to your clients from your server and not from its original location you can just do. however your php.ini settings need to allow external file opens

readfile("http://www.example.com/image.jpg")

correct headers are not required if you are going to display the image in an img tag, altough i would recommend it. you should check the filetype of the image or in most cases just set an octet-stream header so the browser doesnt assume an incorrect type like text or something and tries to display binary data. to do so just do

header("Content-type: application/octet-stream")

one more thing to consider may be setting correct headers for caching...

You need to use

$image = fopen("image.png");
Modify the headers(not sure exacly if it's correct)
headers("Content-type: image/png");
And then send the image
echo fread($image, file_size("image.png"));

Category:php Time:2010-08-06 Views:0
Tags: php

Related post

  • Using ConfigurationManager to load config from an arbitrary location 2008-08-07

    I'm developing a data access component that will be used in a website that contains a mix of classic ASP and ASP.NET pages, and need a good way to manage its configuration settings. I'd like to use a custom ConfigurationSection, and for the ASP.NET p

  • How should I load files into my Java application? 2008-08-09

    How should I load files into my Java application? --------------Solutions------------- The short answer Use one of these two methods: Class.getResource(String) Class.getResourceAsStream(String) For example: InputStream inputStream = YourClass.class.g

  • Mod-Rewrite loading files behind the DocumentRoot 2008-08-12

    I'm using .htaccess and mod_rewrite to point to files that reside behind the DocumentRoot. My folder structure looks like this: home/ webroot/ other_files/ I have a .htaccess file in webroot with the following content: RewriteEngine on RewriteRule ^(

  • "Could not find type" error loading a form in the Designer 2008-08-12

    I have a .NET 2.0 windows forms app, which makes heavy use of the ListView control. I've subclassed the ListView class into a templated SortableListView<T> class, so it can be a bit smarter about how it displays things, and sort itself. Unfortu

  • Replicating load related crashes in non-production environments 2008-08-13

    We're running a custom application on our intranet and we have found a problem after upgrading it recently where IIS hangs with 100% CPU usage, requiring a reset. Rather than subject users to the hangs, we've rolled back to the previous release while

  • How to load plugins in .NET? 2008-08-18

    I'd like to provide some way of creating dynamically loadable plugins in my software. Typical way to do this is using the LoadLibrary WinAPI function to load a dll and calling GetProcAddress to get an pointer to a function inside that dll. My questio

  • IE6 - can't load a normal JPG 2008-08-20

    Try loading in Internet Explorer 6.0. I get an error saying the picture won't load. Try it in any other browser and it works fine. What's wrong? The .jpg file is just a normal picture sitting on the web server. I can even create a simple web page:

  • JavaScript Load Order 2008-08-20

    Hey I am working with both amq.js (ActiveMQ) and Google Maps. I load my scripts in this order <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>AMQ & Maps Demo</title> <!-- Stylesheet --

  • Loading System.ServiceModel configuration section using ConfigurationManager 2008-08-21

    Using C# .NET 3.5 and WCF, I'm trying to write out some of the WCF configuration in a client application (the name of the server the client is connecting to). The obvious way is to use ConfigurationManager to load the configuration section and write

  • Dynamically load a JavaScript file 2008-08-21

    How can you reliably and dynamically load a JavaScript file? This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript library scripts on demand. The client that uses th

  • Loading assemblies and its dependencies 2008-08-22

    My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled with dependencies to other assemblies. The runtime trys to load these from the application directory. But I want to put them into the modul

  • Failed to load resources from resource file 2008-08-25

    Get the following error periodically in an IIS application: Failed to load resources from resource file. The full error message in the Application Event Log is: Event Type: Error Event Source: .NET Runtime Event Category: None Event ID: 0 Date: 8/8/2

  • Dynamically load a class without specifying the assembly 2008-08-25

    Using reflection, how can I get all types that implement an interface with C# 3.0/.NET 3.5 with the least code, and minimizing iterations? This is what I want to re-write: foreach (Type t in this.GetType().Assembly.GetTypes()) if (t is IMyInterface)

  • What causes Visual Studio to fail to load an assembly incorrectly? 2008-08-26

    I had been happily coding along on a decent sized solution (just over 13k LOC, 5 projects) which utilizes Linq to Sql for it's data access. All of sudden I performed a normal build and I received a sweet, sweet ambiguous message: Error 1 Build failed

  • How do I fire an event when a iframe has finished loading in jQuery? 2008-08-27

    I have to load a PDF within a page. Ideally I would like to have a loading animated gif which is replaced once the PDF has loaded. --------------Solutions------------- I'm pretty certain that it cannot be done. Pretty much anything else than PDF work

  • ASP.NET AJAX: Firing an UpdatePanel after the page load is complete 2008-08-28

    I'm sure this is easy but I can't figure it out: I have an ASP.NET page with some UpdatePanels on it. I want the page to completely load with some 'Please wait' text in the UpdatePanels. Then once the page is completely loaded I want to call a code-b

  • Retrieving HTTP status code from loaded iframe with Javascript 2008-08-29

    I used the jQuery Form plugin for asynchronous form submission. For forms that contain files, it copies the form to a hidden iframe, submits it, and copies back the iframe's contents. The problem is that I can't figure out how to find what HTTP statu

  • Debug visualizer - the visualizer dll can't be loaded 2008-08-29

    I am learning to write a debug visualizer in vs2008 C#. But keep getting the error saying that MyDebugVisualizer dll can't be loaded when I am in debug mode and click the magnifying glass icon. My app project is referencing the visualizer project. Be

  • Lazy Loading with a WCF Service Domain Model? 2008-08-30

    I'm looking to push my domain model into a WCF Service API and wanted to get some thoughts on lazy loading techniques with this type of setup. Any suggestions when taking this approach? when I implemented this technique and step into my app, just bef

  • Loading JSON with PHP 2008-09-02

    I've been using PHP for too long, but I'm new to JavaScript integration in some places. I'm trying to find the fastest way to pass database information into a page where it can be modified and displayed dynamically in JavaScript. Right now, I'm looki

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.499 (s). 13 q(s)