Updated php version facing issue now

Discussion in 'PHP' started by Pathan, Aug 9, 2013.

  1. #1
    Hi,

    Recently i updated php version to 5.4 suddenly i have notices server getting overloaded, while checking error_log file its reporting the issue related to the following php code:

    <?php $imagesize = getimagesize($img_src); if($imagesize['0'] > 210): ?>

    I am not good at PHP, can anybody please help me adjusting the above code to work fine with the new version of PHP?
     
    Pathan, Aug 9, 2013 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    Can you provide the error?

    The code also seems to be incomplete / wrong. The snipped you provided will always throw a Parse error: syntax error, unexpected end of file
     
    GMF, Aug 9, 2013 IP
  3. Pathan

    Pathan Well-Known Member

    Messages:
    2,196
    Likes Received:
    218
    Best Answers:
    0
    Trophy Points:
    165
    #3
    Hi,

    The complete coding and error messages are:

     <?php $image = get_post_meta(get_the_ID(), 'image_url', TRUE); ?>                   
                        <?php $cat = ''; if(in_category('Themes')){$cat = 'themes/';} elseif(in_category('Apps')){$cat = 'apps/';} ?>
                        <?php $img_src = get_bloginfo('url') . '/wp-content/uploads/' . $cat . $image; ?>
                        <?php define('TIMBTHUMB', '/includes/timthumb.php?src='); ?>
                       
                        <?php if(!empty($image)): ?>
                       
                            <?php $imagesize = getimagesize($img_src); if($imagesize['0'] > 210): ?>
    PHP:
    and error_log reflects the following:

    [09-Aug-2013 11:09:16 UTC] PHP Warning: getimagesize(http://site.com/wp-content/uploads/themes/Scratched Screen.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: HTTP request failed! in /home/site/public_html/wp-content/themes/mytheme/includes/single/default.php on line 34 
    Code (markup):
    Line 34 has the following coding (already pasted above but let me do it again)

    <?php $imagesize = getimagesize($img_src); if($imagesize['0'] > 210): ?>
    PHP:
    The server is getting overloaded and getting down from the last 12 hours, I am unable to understand how to fix.
     
    Pathan, Aug 9, 2013 IP
  4. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #4
    Mhhh... seems like either the $img_src has a wrong path, or that getimagesize() can't access the path (insufficient permissions).

    Check the path and/or set folder permissions temporary to 777, and look if the error still persists.



    Alternatively, you can disable php error logging for that script with ini_set("log_errors", 0);
     
    GMF, Aug 9, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    The 'real' fix should be to do a is_file($img_src) before you try to access it with getimagesize. While your little snippet doesn't give the whole picture, I get the feeling from things like the endless pointless opening and closing of PHP for no good reason on every blasted line is indicative of deep rooted problems with your entire codebase.

    Of course since this is obviously some code inside turdpress, that kind-of goes without saying.

    That 'empty' on $image should probably be checked FIRST, and where that check is testing is_file($img_src) should be placed instead.

    I'd actually need to see a lot more of the code to weigh in on how it should be handled, but:

    
    <?php
    
    if (!empty($image = get_post_meta(get_the_ID(), 'image_url', TRUE)) {
    	$cat = (
    		in_category('Themes') ? 'themes/' : (
    			in_category('Apps') ? 'apps/' : ''
    		)
    	);
      $img_src = get_bloginfo('url') . '/wp-content/uploads/' . $cat . $image;
      define('TIMBTHUMB', '/includes/timthumb.php?src=');
    	if (is_file($img_src)) {
    		$imagesize = getimagesize($img_src);
    		if ($imagesize['0'] > 210) {
    Code (markup):
    Would be a good start -- naturally you'd have to keep going on stripping out all the stupid malfing <?php ?> "for nothing" that are in there, and add a else handler for when there's an error trying to process the image at the appropriate spot.
     
    deathshadow, Aug 9, 2013 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    ThePHPMaster, Aug 11, 2013 IP