Solved

curl filetime with dynamic images

Posted on 2011-03-06
4
1,036 Views
Last Modified: 2012-05-11
I have a script that uses curl to check the modified time of a file on a remote server.
<?

$curl = curl_init("http://perfectweb.com/experts/curl_time/oh_noes.jpg");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FILETIME, true);
$result = curl_exec($curl);

if ($result === false) {
	die (curl_error($curl)); 
}

if (curl_error($curl))  echo curl_error($curl);
		
$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
if ($timestamp != -1) { //otherwise unknown
	echo date("Y-m-d H:i:s", $timestamp); //etc
}

?>

Open in new window


It works great if I point it to a jpg on my server, as shown above. Now I want to combine it with a dynamic image script that looks like this:
<?

## eventually this script will deliver different images, but one image is hard coded for now
$filename = 'oh_noes.jpg';

header("Content-type: image/jpg");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\"");
readfile("$filename") or display_error('The file could not be found.');
exit;

?>

Open in new window

(I have this script saved with a ".jpg" extension and forced to run as PHP with htaccess.)

The image script works great when called directly, but now I want to combine the two. If I try to use the file time script with the dynamic image script, it doesn't work. How can I make CURLOPT_FILETIME work with a jpg delivered by a PHP script? Is there a way to detect an incoming CURLOPT_FILETIME request and send the right headers to make curl happy?
0
Comment
Question by:merwetta1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 450 total points
ID: 35052614
You want to return a header like this, after getting the modified date of the local file:

Last-Modified: Sat, 05 Mar 2011 03:35:19 GMT

Open in new window

0
 
LVL 10

Assisted Solution

by:honestman31
honestman31 earned 50 total points
ID: 35052637
try this  header
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 450 total points
ID: 35052817
Also, within the "jpg" server

$_SERVER['REQUEST_METHOD']

Open in new window

can be tested for 'GET' vs 'HEAD' to know whether to return the file contents.
0
 
LVL 6

Author Closing Comment

by:merwetta1
ID: 35054691
I'm now using $_SERVER['REQUEST_METHOD'] to detect CURL FILETIME requests and return the date modified header and exit. It all works. Thank you.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question