pda4me
asked on
PHP, optimize code snippet using another call?
I am currently using the following code snip to check to see if a file exists in a large image directory. The fact that I am using a URL instead of a direct path on the server I think is slowing it down...is it possible to change the file_get_contents to another call and reference the file system path instead? If so, how do I do this?
<?
$url = "http://www.mysite.com/feeds/sancap/rets_images/";
for($c=1;$c<30;$c++){
if($c<10){
$c_ext = "0".$c;
}else{
$c_ext = $c;
}
if (file_get_contents($url."{$MLNumber}_{$c_ext}.jpg")){
$image_array[$c_ext] = "{$MLNumber}_{$c_ext}.jpg";
}
}
krsort($image_array);
$image_array[] = "{$MLNumber}.jpg";
$img_cnt = 1;
$image = "<br>";
foreach($image_array as $key => $value){
$image .= "<a href=/feeds/sancap/rets_images/".$value." rel=\"enlargeimage\" rev=\"targetdiv:loadarea\">";
$image .= "<img src=/feeds/sancap/rets_images/".$value." alt='' width='100' height='75' border='0' />";
$image .= "</a> ";
$img_cnt++;
}
?>
ASKER
close, but it seems to only show the thumbnail $MLNumber.jpg and no other? it seems to be missing the other thumbnails?
Ok, just so i understand you correctly...
Is your original code working, but this is not?
Is your original code working, but this is not?
<?
$url = 'feeds/sancap/rets_images/';
for($c=1;$c<30;$c++){
if($c<10){
$c_ext = "0".$c;
}else{
$c_ext = $c;
}
if (is_file($url."{$MLNumber}_{$c_ext}.jpg")){
$image_array[$c_ext] = "{$MLNumber}_{$c_ext}.jpg";
}
}
krsort($image_array);
$image_array[] = "{$MLNumber}.jpg";
$img_cnt = 1;
$image = "<br>";
foreach($image_array as $key => $value){
$image .= "<a href=/feeds/sancap/rets_images/".$value." rel=\"enlargeimage\" rev=\"targetdiv:loadarea\">";
$image .= "<img src=/feeds/sancap/rets_images/".$value." alt='' width='100' height='75' border='0' />";
$image .= "</a> ";
$img_cnt++;
}
?>
ASKER
Yes, original code is working fine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
Remember that file path is relative to where script is.
Use "is_file" instead of "file_get_contents" to speed things up even more.
Open in new window