White_Lily Posted November 14, 2012 Share Posted November 14, 2012 (edited) Okay, so i have written a php calculation that determines what the margin left and top will be of a users avatar. I have a slight problem in the way that the script can't find the image to get the size of it. The Error: Warning: getimagesize(http://janedealsart.co.uk/social/users/Guest/uploads/50a3c6fe2a699.jpg) [function.getimagesize]: failed to open stream: Connection refused in /home/sites/janedealsart.co.uk/public_html/social/profile.php on line 22 This is the code I have written for it: $getbg = select("*", "users", "username = '$u'"); $bg = mysql_fetch_assoc($getbg); $pic = $bg["background"]; $propicmargin = $bg["avatar"]; if($propicmargin){ list($width, $height) = getimagesize($propicmargin); // <-- LINE 22 /*//Calculates Height of images that have an exact width of the box. if($width == 166){ $margin = 166-$height; $margin = $margin/2; if($margin < 0){ $margin = 0; } }*/ //Calculates Width & Height of small images to find the margin left & top. if($width < 166 && $height < 166){ $margin = 166-$height; $margin = $margin/2; if($margin <= 0){ $margin = 0; } $marginw = 166-$width; $marginw = $marginw/2; if($marginw <= 0){ $marginw = 0; } } $avatar = '<img src="'.$propicmargin.'" />'; }else{ $avatar = '<img src="'.$GLOBALS["nav"].'images/avatar.png" />'; } Any Ideas? Folder permissions are 777. The image exists and the file path is correct. Edited November 14, 2012 by White_Lily Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 The image exists and the file path is correct. Double check and make sure that the script can access the image with the path provided. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 I copied and pasted the file path into the browser tab and the correct image came up, so other than that im not entirely sure what you mean? Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 Why don't you just use the filename, instead of the full URL? Quote Link to comment Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 because each user has his/her own directory, it isnt just a single imagethats being calcuated, the image that is uploaded by the user could be 45px x 9px, or 165px x 164px Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 (edited) That doesn't explain why you're using a URL instead of a FILENAME/path. Edited November 14, 2012 by Jessica Quote Link to comment Share on other sites More sharing options...
Scott_S Posted November 14, 2012 Share Posted November 14, 2012 the error is " failed to open stream: Connection refused", your web host has security measures in place. The easiest way around this is to take Jessica's suggestion. There is a configuration to add your host/domain as trusted but that varies from host to host. You could use curl(). Quote Link to comment Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 Okay so i took jess' advice and used a path, the connection error disappeared but it is still not caluclating the width and height of the image. The path i used is: $doc = $_SERVER['DOCUMENT_ROOT']."social/users/".$u."/uploads/".$new_filename; Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 What debugging steps have you taken? Quote Link to comment Share on other sites More sharing options...
Scott_S Posted November 14, 2012 Share Posted November 14, 2012 are there any values in $width or $height right after calling getimagesize()? Quote Link to comment Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 Scott, sorry if this sounds rude, but if there were values in $width and $height I wouldn't really be posting here. Simply because if there were values in both variables then my problem would be around the actual maths part itself, this means just reconsidering the logic of events in the equation. AyKay47, I have used php.ini (this is where the original connection error came from) i have used mysql_error() on the select function, and have echoed all variables possible for values, the only variables that I am concerned about is the $width, $height, and the getimagesize() php function, as these don't have any values, or have the wrong values. I have also checked the path/url provided to getimagesize() and the image existed and shows in the browser. Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 Did you read the notes on list? I wonder if the fact that getimagesize returns an array with 7 indices and you're only giving list two variables and list goes right-left, would affect it. What happens if you just print_r() the returned array from getimagesize? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 15, 2012 Share Posted November 15, 2012 (edited) list() assigns the values from right to left, however the only time you actually need to worry about that is when you pass arrays with indices into the function. The OP is using list() correctly here. Refer to php.net Example#1. White_lily I ask what debugging steps you have taken because we need to know exactly where this code is failing. If you have "echoed all variables possible for values" then you should know where the code is failing. What is the value of $propicmargin? Add a condition to determine whether getimagesize() is working correctly: $size = getimagesize($propicmargin); if(!$size) { die("Could not find the size of file:<br />" . $propicmargin); } If the above code passes, $width and $height will be assigned values. Edited November 15, 2012 by AyKay47 Quote Link to comment Share on other sites More sharing options...
White_Lily Posted November 15, 2012 Author Share Posted November 15, 2012 (edited) Okay I have it sorted. I needed to use a file path instead of a URL, but DOCUMENT_ROOT didn't work, code below: <?php $doc = "users/".$u."/uploads/"; if(!empty($_POST['imgsubmit'])){ if (isset ($_FILES['new_image'])){ $imagename = $_FILES['new_image']['name']; $parts = explode( '.', $imagename ); $extension = strtolower( $parts['1'] ); $new_filename = uniqid().".".$extension; $source = $_FILES['new_image']['tmp_name']; $target = $doc.$new_filename; move_uploaded_file($source, $target); $imagepath = $new_filename; $save = $doc.$imagepath; //This is the new file you saving $file = $doc.$imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 166; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; if(!empty($width)){ $imageavi = $doc.$imagepath; $changeavi = update("users", "avatar = '$imageavi'", "username = '$u'") or die(mysql_error()); if($changeavi){ echo "Avatar Changed!"; } }else{ } } } ?> I hate PHP >_> lol Edited November 15, 2012 by White_Lily Quote Link to comment 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.