?
Solved

curl filetime with dynamic images

Posted on 2011-03-06
4
Medium Priority
?
1,055 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 1800 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 200 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 1800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

766 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