Janice Posted March 21, 2007 Share Posted March 21, 2007 I have a php verification / landing verification / image verification page. It worked fine before,Now i get this error after uploading and I dont see the image.Warning: imagepng() [function.imagepng]: Unable to open 'images/b804e0.png' for writing in /home/megax/public_html/include/functions.php on line 114What would be wrong? Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 21, 2007 Share Posted March 21, 2007 Could you please show line 114 Link to comment Share on other sites More sharing options...
Janice Posted March 21, 2007 Author Share Posted March 21, 2007 functions.php <?phpfunction standardheader($title) {?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xtml" xml:lang="en" lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title><?php echo $title; ?></title></head><body><?php}function stdfoot() {?></body><html><?php} class ocr_captcha { var $key; // ultra private static text var $long; // size of text var $lx; // width of picture var $ly; // height of picture var $nb_noise; // nb of background noisy characters var $filename; // file of captcha picture stored on disk var $imagetype="png"; // can also be "png"; var $public_key; // public key var $font_file="./include/adlibn.ttf"; function ocr_captcha($long=6,$lx=120,$ly=30,$nb_noise=25) { $this->key=md5("A nicely little text to stay private and use for generate private key"); $this->long=$long; $this->lx=$lx; $this->ly=$ly; $this->nb_noise=$nb_noise; $this->public_key=substr(md5(uniqid(rand(),true)),0,$this->long); // generate public key with entropy } function get_filename($public="") { if ($public=="") $public=$this->public_key; return "images/".$public.".".$this->imagetype; } // generate the private text coming from the public text, using $this->key (not to be public!!), all you have to do is here to change the algorithm function generate_private($public="") { if ($public=="") $public=$this->public_key; return substr(md5($this->key.$public),16-$this->long/2,$this->long); } // check if the public text is link to the private text function check_captcha($public,$private) { // when check, destroy picture on disk if (file_exists($this->get_filename($public))) unlink($this->get_filename($public)); return (strtolower($private)==strtolower($this->generate_private($public))); } // display a captcha picture with private text and return the public text function make_captcha($noise=true) { $private_key = $this->generate_private(); $image = imagecreatetruecolor($this->lx,$this->ly); $back=ImageColorAllocate($image,intval(rand(224,255)),intval(rand(224,255)),intval(rand(224,255))); ImageFilledRectangle($image,0,0,$this->lx,$this->ly,$back); if ($noise) { // rand characters in background with random position, angle, color for ($i=0;$i<$this->nb_noise;$i++) { $size=intval(rand(6,14)); $angle=intval(rand(0,360)); $x=intval(rand(10,$this->lx-10)); $y=intval(rand(0,$this->ly-5)); $color=imagecolorallocate($image,intval(rand(160,224)),intval(rand(160,224)),intval(rand(160,224))); $text=chr(intval(rand(45,250))); ImageTTFText ($image,$size,$angle,$x,$y,$color,$this->font_file,$text); } } else { // random grid color for ($i=0;$i<$this->lx;$i+=10) { $color=imagecolorallocate($image,intval(rand(160,224)),intval(rand(160,224)),intval(rand(160,224))); imageline($image,$i,0,$i,$this->ly,$color); } for ($i=0;$i<$this->ly;$i+=10) { $color=imagecolorallocate($image,intval(rand(160,224)),intval(rand(160,224)),intval(rand(160,224))); imageline($image,0,$i,$this->lx,$i,$color); } } // private text to read for ($i=0,$x=5; $i<$this->long;$i++) { $r=intval(rand(0,128)); $g=intval(rand(0,128)); $b=intval(rand(0,128)); $color = ImageColorAllocate($image, $r,$g,$; $shadow= ImageColorAllocate($image, $r+128, $g+128, $b+128); $size=intval(rand(12,17)); $angle=intval(rand(-30,30)); $text=strtoupper(substr($private_key,$i,1)); ImageTTFText($image,$size,$angle,$x+2,26,$shadow,$this->font_file,$text); ImageTTFText($image,$size,$angle,$x,24,$color,$this->font_file,$text); $x+=$size+2; } if ($this->imagetype=="jpg") imagejpeg($image, $this->get_filename(), 100); else imagepng($image, $this->get_filename()); ImageDestroy($image); } function display_captcha($noise=true) { $this->make_captcha($noise); $res="<input type=hidden name='public_key' value='".$this->public_key."'>\n"; $res.="<img align=middle src='".$this->get_filename()."' border='0'>\n"; return $res; } }?> Link to comment Share on other sites More sharing options...
PrateekSaxena Posted March 21, 2007 Share Posted March 21, 2007 You expect us to count till 114? Is there something very obvious that I am missing here? Link to comment Share on other sites More sharing options...
Anders Moen Posted March 21, 2007 Share Posted March 21, 2007 http://norskwebforum.no/pastebin/7944I know the site is in Norwegian, but I suppose you can figure out where the code is :)That's with line-numbers. Link to comment Share on other sites More sharing options...
Janice Posted March 21, 2007 Author Share Posted March 21, 2007 You expect us to count till 114? Is there something very obvious that I am missing here?I hope I would get a good reply from someone who really knows what the issue is Link to comment Share on other sites More sharing options...
justsomeguy Posted March 21, 2007 Share Posted March 21, 2007 This is the error message: Warning: imagepng() [function.imagepng]: Unable to open 'images/b804e0.png' for writing in /home/megax/public_html/include/functions.php on line 114It can't create the image file to write to. Either it would not have permission to do this or the path is incorrect, if permissions were the problem I think it would specify that. I suspect the path because it might be trying to open a file in a folder called images inside the include folder, and I'm thinking the images and include folders are parallel, not nested. There is a function in the captcha class called get_filename that looks like this:function get_filename($public="") { if ($public=="") $public=$this->public_key; return "images/".$public.".".$this->imagetype; } Change this function to return the absolute path instead of a relative path. That would make it like this: function get_filename($public="") { if ($public=="") $public=$this->public_key; return "/home/megax/public_html/images/".$public.".".$this->imagetype; } Reply back if that works. Link to comment Share on other sites More sharing options...
Janice Posted March 30, 2007 Author Share Posted March 30, 2007 This is the error message:It can't create the image file to write to. Either it would not have permission to do this or the path is incorrect, if permissions were the problem I think it would specify that. I suspect the path because it might be trying to open a file in a folder called images inside the include folder, and I'm thinking the images and include folders are parallel, not nested. There is a function in the captcha class called get_filename that looks like this:function get_filename($public="") { if ($public=="") $public=$this->public_key; return "images/".$public.".".$this->imagetype; } Change this function to return the absolute path instead of a relative path. That would make it like this: function get_filename($public="") { if ($public=="") $public=$this->public_key; return "/home/megax/public_html/images/".$public.".".$this->imagetype; } Reply back if that works. thanks alot justsomeguy .. you are always informative..it worked fine when I set 777 permissions to "images" folder but I know it is not safe!I will try your codings and let you know Link to comment Share on other sites More sharing options...
Janice Posted March 30, 2007 Author Share Posted March 30, 2007 I have another doubt..Email ID:</b><input type="text" name="email" size="20" />this will give output with a box for email id to be entered..how to make it show without a box? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2007 Share Posted April 2, 2007 Try setting the permission to 0755 instead of 0777 and see if that works, it would be better then giving full access to everyone. I'm not sure what you're asking about the email question. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now