Error when using Text_CAPTCHA

From: Date: Sun, 08 Apr 2012 12:30:46 +0000
Subject: Error when using Text_CAPTCHA
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-31509@lists.php.net to get a copy of this message
Hello. I run into an error when using an example from a book. I have a file named spamTest.php with this source code: ?php session_start(); ?> <!DOCTYPE html> <html dir="ltr" lang="nb-NO"> <head> <meta charset="UTF-8" /> <title>SpamTest</title> </head> <body> <?php if(!isset($_POST['captcha'])){ require_once('Text/CAPTCHA.php'); $options = array( 'font_size' => 32, 'font_path' => '/home/test/public_html', 'font_file' => 'arial.ttf' ); $formCAPTCHA = Text_CAPTCHA::factory('Image'); $result = $formCAPTCHA->init(300, 120, null, $options); if (PEAR::isError($result)) { echo 'Sorry, there was a problem generating the CAPTCHA Object'; exit; } // Store the generated phrase in a session // variable so that we can get to it later $_SESSION['secretCAPTCHA'] = $formCAPTCHA->getPhrase(); $imageCAPTCHA = $formCAPTCHA->getCAPTCHAAsJPEG(); if (PEAR::isError($imageCAPTCHA)) { echo 'Sorry, there was a problem generating the CAPTCHA Image'; exit; } // We use an MD5 of the generated phrase as a unique filename file_put_contents(md5($formCAPTCHA->getPhrase()) . '.jpg', $imageCAPTCHA); ?> <p> Enter the phrase in the box below: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <img src="<?php echo md5($formCAPTCHA->getPhrase()); ?>.jpg" width="300" height="120" /><br /> <input type="text" name="captcha" /><br /> <input type="submit" value="Validate" /> </form> </p> <?php } else { // Form has been submitted with a CAPTCHA value if (isset($_POST['captcha']) && isset($_SESSION['secretCAPTCHA']) && strlen($_POST['captcha']) > 0 && strlen($_SESSION['secretCAPTCHA']) > 0 && $_POST['captcha'] == $_SESSION['secretCAPTCHA']) { echo "Congratulations!"; unlink(md5($_SESSION['secretCAPTCHA']) . '.jpg'); } else { echo "Sorry, that is not correct."; } } ?> </body> </html> But when running this pages i got error message shown below: Warning: file_put_contents(f2438c70d763b785d949c58676eada8c.jpg) [function.file-put-contents]: failed to open stream: Permission denied in /home/test/public_html/spamTest.php on line 31 Why happen this? What can I do? Thanks for your time. Karl -- Hjemmeside: http://www.karl-arne.name/ Homepage: http://blog.karl-arne.name/

« previous php.pear.general (#31509) next »