serien Posted March 12, 2013 Share Posted March 12, 2013 I'm truly sorry if this is a repeat but I have searched and searched, but no answers seem to be helping my issue >< I'm either missing something really idiotic or my case is for some reason different. I am trying to save a generated 'GD' image using the file_get_contents function. However, I keep getting the following error: Warning: file_get_contents(../images/ha/haimg.php?skin=ff00ff): failed to open stream: No error in C:\wamp\www\dellusionary\classes\user_class.php on line 98 I have been stuck for hours... the image path should be correct. I've tried using the full path as well, "/dellusionary/images/ha/haimg.php?skin=ff00ff", but that doesn't help. I have also made sure that security settings on both the copy-from and copy-to files are read/write for all user groups. I am stumped ;.; Here's code //=========================================== The Image Creation Function ====================== public function updateha($skin) { $url = "../images/ha/haimg.php?skin=$skin"; $img = "../images/ha/users/".$this->userid.".png"; if(file_put_contents($img, file_get_contents($url)) ) // { return "<div id='alert'>Avatar successfully updated!</div>"; } else { return "<div id='warning'>I'm sorry, there has been an error while saving the image.</div>"; } } //======================================= The Actual Image File ================================== <?php //-------- VARIABLES! $skintone = ($_GET["skin"] != '') ? $_GET["skin"] : "0f0f0f"; // Create Base $basepath = 'http://localhost/dellusionary/images/ha/bases/female/fembasetorso.png'; $base = imagecreatefrompng($basepath); colorize($base,$skintone); list($width, $height) = getimagesize($basepath); // Merge Legs onto base $legpath = 'http://localhost/dellusionary/images/ha/bases/female/fembaselegs.png'; $legs = imagecreatefrompng($legpath); colorize($legs,$skintone); merge($base,$legs); // Add Body Lines $lines = 'http://localhost/dellusionary/images/ha/bases/female/femlinestorso.png'; $l = imagecreatefrompng($lines); merge($base,$l); // Add Leg Lines $lines2 = 'http://localhost/dellusionary/images/ha/bases/female/femlineslegs.png'; $l2 = imagecreatefrompng($lines2); merge($base,$l2); /* Output Image */ imageAlphaBlending($base, true); imageSaveAlpha($base, true); header('Content-Type: image/png'); imagepng($base); imagedestroy($base); /*---------------------------------------- Image Manip Functions --------------- */ function colorize(&$image, $color) { // Define RGB Values $red = hexdec(substr($color, 0, 2)); $green = hexdec(substr($color, 2, 2)); $blue = hexdec(substr($color, 4, 2)); // Colorize Layer imagealphablending($image, false); for ($x = imagesx($image); $x-- { for ($y = imagesy($image); $y-- { $rgb = imagecolorat($image, $x, $y); $c = imagecolorsforindex($image, $rgb); if ($c['red'] < 256 && $c['green'] < 1 && $c['blue'] < 1) { // dark colors // here we use the new color, but the original alpha channel $colorB = imagecolorallocatealpha($image, $red, $green, $blue, $c['alpha']); imagesetpixel($image, $x, $y, $colorB); } } } } function merge(&$base, $add) { imagealphablending($base, true); imagesavealpha($base, true); imagecopy($base, $add, 0, 0, 0, 0, imagesx($base), imagesy($base)); imagedestroy($add); } ?> Any help would be sincerely appreciated!!!! Quote Link to comment https://forums.phpfreaks.com/topic/275533-php-image-help/ Share on other sites More sharing options...
serien Posted March 12, 2013 Author Share Posted March 12, 2013 Quick update after a few more hours of searching I determined that the problem lies in my file_get_contents($url) returning an empty string. Not sure what is causing this, as when I type in the url of image directly into the address bar I definitely get an image. The file should also be readable, I have the permissions set to everything available for everone on it. I tried also using Curl instead of the file method, all to no avail. Everything is enabled, cannot for the life of me figure this darn thing out! Quote Link to comment https://forums.phpfreaks.com/topic/275533-php-image-help/#findComment-1418120 Share on other sites More sharing options...
Solution ignace Posted March 12, 2013 Solution Share Posted March 12, 2013 ../images/ha/haimg.php?skin=$skin refers to a local path. http://domain.top/images/ha/haimg.php?skin=$skin is an actual URL where ?skin= actually works. Quote Link to comment https://forums.phpfreaks.com/topic/275533-php-image-help/#findComment-1418126 Share on other sites More sharing options...
serien Posted March 12, 2013 Author Share Posted March 12, 2013 Thanks for the help! I had tried to do absolute paths using some global variables that I have set. This time I typed them in directly. The error changed! Warning: file_put_contents(http://localhost/dellusionary/images/ha/users/2.png): failed to open stream: HTTP wrapper does not support writeable connections in C:\wamp\www\dellusionary\classes\user_class.php on line 98 Turns out I need the direct path for the write-from file and the indirect path from the write-to file. Just needed to try that combination haha. Thank you so much!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/275533-php-image-help/#findComment-1418182 Share on other sites More sharing options...
ignace Posted March 12, 2013 Share Posted March 12, 2013 $url has to be an actual URL where as $img has to be a local path. Quote Link to comment https://forums.phpfreaks.com/topic/275533-php-image-help/#findComment-1418206 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.