1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
function getPostImages($idPost,$date,$just_one=false,$thumb=false){
$no_pic=SITE_URL."/images/no_pic.png";
$date = standarizeDate($date);
$date=explode('-',$date);
if (count($date)==3){//is_date
$types=split(",",IMG_TYPES);//creating array with the allowed images types
$imgUrl=SITE_URL.IMG_UPLOAD;//url for the image
$imgPath=IMG_UPLOAD_DIR;//path of the image
$imgDir=$date[2].'/'.$date[1].'/'.$date[0].'/'.$idPost.'/'; //$imgDir=$idPost.'/';
$files = scandir($imgPath.$imgDir);
foreach($files as $img){//searching for images
$file_ext = strtolower(substr(strrchr($img, "."), 1 ));//get file ext
if (in_array($file_ext,$types))$images[]=$img;//we only keep images with allowed ext
}
//print_r($images);
if (count($images)>0){//there's at least 1 image
foreach($images as $img){
$is_thumb=(substr($img,0,6)=='thumb_');
if ($just_one){//we want just one image
if (!$thumb && !$is_thumb) return $imgUrl.$imgDir.$img;//first image match
elseif($thumb && $is_thumb) return $imgUrl.$imgDir.$img;//first thumb match
}
else{//we want all the images
if (!$thumb && !$is_thumb) {//images and thumbs
$r_images[]=array($imgUrl.$imgDir.$img,$imgUrl.$imgDir.'thumb_'.$img);//images array
}
elseif($thumb && $is_thumb){//only thumbs
$r_images[]=$imgUrl.$imgDir.$img;//thumbs array
}
}
}
}
elseif($thumb) return $no_pic;//nothing in the folder
return $r_images;
}//no date :(
else return $no_pic;
} |