roopurt18 Posted May 24, 2007 Share Posted May 24, 2007 Our site allows clients to upload files to share with others. We have several clients who are sharing many files with many users. There is one client that inconsistently receives a blank white screen while viewing a file. She is the only client that has reported this as an issue, so I'm not sure how wide spread it is; I can not duplicate this problem myself but I can watch it happen to her using remote desktop software. She first reported it last week. I went into the function that serves the file, added two lines of code, removed those same two lines, saved the file, and the problem went away. She called again this morning reporting the same problem. This time I modified the code to pass along extra header information and that seemed to clear the problem up. She called again about 2 or 3 hours later and the problem had started yet again, without any changes to the code. Here is the original function that serves the file: <?php // ShowUploadedDoc // $doc_id - the id of the document // Pass the document through to the viewer function ShowUploadedDoc($doc_id){ $fp = @fopen(SUBVIEW_DATA_PATH . $doc_id,'r'); $conttype = CFileManagerDAO::_GetMime($doc_id, SUBVIEW_DATA_PATH); $fp = @fopen(SUBVIEW_DATA_PATH . $doc_id,'r'); header('Content-type: '.$conttype['full']); header('Content-length: '.(string)(@filesize(SUBVIEW_DATA_PATH . $doc_id))); @fpassthru($fp); return; } ?> Here is the new function: <?php // ShowUploadedDoc // $doc_id - the id of the document // Pass the document through to the viewer function ShowUploadedDoc($doc_id){ $doc = @SubviewDocumentDAO::GetDocument($doc_id); $conttype = @CFileManagerDAO::_GetMime($doc_id, SUBVIEW_DATA_PATH); $fp = @fopen(SUBVIEW_DATA_PATH . $doc_id,'r'); $cname = $doc["doc_name"]; $ctype = $conttype["full"]; $clen = (string)(@filesize(SUBVIEW_DATA_PATH . $doc_id)); @header("Content-disposition: attachment; filename=\"{$cname}\""); @header("Cache-Control: cache, must-revalidate"); @header("Content-type: {$ctype}"); @header("Content-Length: {$clen}"); @header("Pragma: public"); @header("Expires: 0"); @fpassthru($fp); exit(); } ?> Suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/52886-solved-blank-screen-while-serving-file/ Share on other sites More sharing options...
MadTechie Posted May 24, 2007 Share Posted May 24, 2007 could it be a caching issue ? you could try script.php?rnd=54632627 Quote Link to comment https://forums.phpfreaks.com/topic/52886-solved-blank-screen-while-serving-file/#findComment-261163 Share on other sites More sharing options...
utexas_pjm Posted May 25, 2007 Share Posted May 25, 2007 If for any reason PHP couldn't get handle on any of these files $fp would not be a valid resource, but you would never know because you are supressing the errors and not doing any error checking. I'd do something like: <?php // ... $fp = @fopen(SUBVIEW_DATA_PATH . $doc_id,'r'); if(!is_resource($fp)){ Logger::logError('Invalid handle: ' . __FILE__ .'('.__LINE__.')'); return; } // ... I don't know if this actually causing the problem, but just as a sanity check you might want to look into it --as I could see this resulting in a blank screen. Patrick Quote Link to comment https://forums.phpfreaks.com/topic/52886-solved-blank-screen-while-serving-file/#findComment-261250 Share on other sites More sharing options...
roopurt18 Posted May 25, 2007 Author Share Posted May 25, 2007 I've removed all of the @ symbols and placed this at the top of the function: <?php // %% set_error_handler to debug problem, restore_error_handler // %% below $f = create_function('', 'echo "an error occured"; exit();'); // %% temp error handler set_error_handler("{$f}"); // %% temp error handler ?> and this at the bottom: <?php fpassthru($fp); restore_error_handler(); // %% remove when we remove set_error_handler exit(); ?> Hopefully this will help me determine if its a browser or server issue. Quote Link to comment https://forums.phpfreaks.com/topic/52886-solved-blank-screen-while-serving-file/#findComment-261680 Share on other sites More sharing options...
roopurt18 Posted May 25, 2007 Author Share Posted May 25, 2007 Hah! So there was an error! <?php $divs = explode(";", $some_var); $ext = trim($divs[1]); ?> The assignment to $ext was giving an "index out of bounds" error when $some_var didn't have a semi-colon in it. Quote Link to comment https://forums.phpfreaks.com/topic/52886-solved-blank-screen-while-serving-file/#findComment-261726 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.