SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Photopost Feature on vB

    First of all I am not a programmer, just a technical professional, i.e. network admin. I run a large vBuletin board on a dedicated Linux server (7 years old) and I am capable of editing PHP code, but not writing anything from scratch...here is my issue:

    I have a problem with some missing attachments...Is there a way to put a if/then or else in the PHP code so that when the attachment is missing I can return something other than this error:

    Warning: fopen(/home/admin/attachments/2/5283.attach) [function.fopen]: failed to open stream: No such file or directory in /attachment.php on line 203

    That is what you get when you click the attachment link in a post where the actual file is missing. I would just like to have it give a message like: this attachment is no long available, or something like that on a standard vB page so it does not look like the board is messed up.

    Thank for anyone that can/will help me!

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not familiar with the way vbulletin displays attachments but you could try something like this..
    Code PHP:
    if (@fopen(FILE))
    //do something
    else
    //couldnt open file do somethine else

    @ supresses the error

  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply, here is the code starting on line 203 in attachment.php where that error starts:

    HTML Code:
    if (!($fp = fopen($attachpath, 'rb')))
    		{
    			exit;
    		}
    	}
    	else if (!($fp = @fopen($attachpath, 'rb')))
    	{
    		$filedata = base64_decode('R0lGODlhAQABAIAAAMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
    		$filesize = strlen($filedata);
    		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');             // Date in the past
    		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    		header('Cache-Control: no-cache, must-revalidate');           // HTTP/1.1
    		header('Pragma: no-cache');                                   // HTTP/1.0
    		header("Content-disposition: inline; filename=clear.gif");
    		header('Content-transfer-encoding: binary');
    		header("Content-Length: $filesize");
    		header('Content-type: image/gif');
    		echo $filedata;
    		exit;
    	}
    }
    do you know where I would put the else statement?

  4. #4
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe something like this...

    Code PHP:
    if (!($fp = @fopen($attachpath, 'rb')))
    		{
    			exit;
    		}
    	}
    	else if (!($fp = @fopen($attachpath, 'rb')))
    	{
    		$filedata = base64_decode('R0lGODlhAQABAIAAAMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
    		$filesize = strlen($filedata);
    		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');             // Date in the past
    		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    		header('Cache-Control: no-cache, must-revalidate');           // HTTP/1.1
    		header('Pragma: no-cache');                                   // HTTP/1.0
    		header("Content-disposition: inline; filename=clear.gif");
    		header('Content-transfer-encoding: binary');
    		header("Content-Length: $filesize");
    		header('Content-type: image/gif');
    		echo $filedata;
    		exit;
    	}
    }
    else {
       echo 'invalid attachment';
    }

  5. #5
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, that did not work, plus it would need to call up a vB error page.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •