eddyys Posted December 17, 2010 Share Posted December 17, 2010 Hi guys, first time on forum, and in desperate need of help. I asked my co workers and they don't have a single clue into what is going wrong. I built a PHP image handler to secure images down to the user too see. When I integrate this into the ajax however, the images only load on the page after all the ajax requests finish. In this case there are 4 ajax requests. I have attached screenshots of the problem before all the ajax requests finish and after. NOTE: This works fine with images that are not being generated PHP. At first I thought it might be a header problem with the image handler but I cant seem to find any people who have seen this problem. Here is the code. class SecureImage { public $user_img_dir; public $db_img_dir; public $temp_img_dir; public $main_img_dir; function __construct(){ global $SESSION; //set the class vars $this->temp_img_dir = BASE_PATH.'webdocs/images/_temp/'; $this->main_img_dir = '/var/images/'; //now check to see if there is a directory for this file //build the directory for the image $user_id = $SESSION->getUserid(); $db_name = $GLOBALS['Config']->db['db_name']; $user_img_dir = "{$this->main_img_dir}{$db_name}/{$user_id}/"; $db_img_dir = $this->main_img_dir.$db_name."/"; //set the class vars $this->user_img_dir = $user_img_dir; $this->db_img_dir = $db_img_dir; //now check to see if the directory is there if(!is_dir($user_img_dir)){ //check to see if the db_name is a dir if(!is_dir($db_img_dir)){ //make the directory mkdir($db_img_dir); } //now make the user id dir mkdir($user_img_dir); } } public function getImage($img){ $img_array = explode('.', $img); switch($img_array[1]){ case 'jpg': case 'jpeg': header('Content-Type: image/jpeg'); break; case 'png': header('Content-Type: image/png'); break; case 'gif': header('Content-Type: image/gif'); break; } header('Content-Disposition: inline;'); //get the file size $img_size = filesize($this->user_img_dir.$img); header('Content-Length: '.$img_size); echo readfile($this->user_img_dir.$img); } } If anyone has any ideas, much appreciated. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/222002-image-handlerajax-problems/ Share on other sites More sharing options...
eddyys Posted December 17, 2010 Author Share Posted December 17, 2010 bump Link to comment https://forums.phpfreaks.com/topic/222002-image-handlerajax-problems/#findComment-1148772 Share on other sites More sharing options...
eddyys Posted December 21, 2010 Author Share Posted December 21, 2010 bump Link to comment https://forums.phpfreaks.com/topic/222002-image-handlerajax-problems/#findComment-1149953 Share on other sites More sharing options...
eddyys Posted December 22, 2010 Author Share Posted December 22, 2010 bump Link to comment https://forums.phpfreaks.com/topic/222002-image-handlerajax-problems/#findComment-1150298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.