Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/52886-solved-blank-screen-while-serving-file/
Share on other sites

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

 

 

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.