Mutley Posted February 3, 2009 Share Posted February 3, 2009 Trying to upload an image and get the following error: Warning: fopen(1b823dd333cd6295592e170c0a939d7e.jpg) [function.fopen]: failed to open stream: Permission denied in /home/sfengine/public_html/admin/includes/global.inc.php on line 68 Warning: fwrite(): supplied argument is not a valid stream resource in /home/sfengine/public_html/admin/includes/global.inc.php on line 69 Warning: fclose(): supplied argument is not a valid stream resource in /home/sfengine/public_html/admin/includes/global.inc.php on line 70 Unable to open the file: 1b823dd333cd6295592e170c0a939d7e.jpg The folder is set to CHMOD 777. The upload script is: <h2>Add Category</h2> <?php if($_POST['action'] == 'add_cat'){ $cat_name = $_POST['cat_name']; $cat_description = $_POST['cat_description']; $cat_image = $_FILES['cat_image']; //Image Types $AllowedImages = array('image/jpeg','image/pjpeg'); if(empty($cat_name) || empty($cat_description) || $cat_image['error'] != 0 || !in_array($cat_image['type'], $AllowedImages)){ echo '<p>Please fill in all fields correctly.</p>'; } else{ //Continue & Add to DB $cat_image_name = md5(microtime()).'.jpg'; //Write Original File WriteFile($cfg['catimages']['folder'].$cat_image_name, file_get_contents($cat_image['tmp_name'])); //Create smaill sized thumbnail $ImageFunctions->Open($cfg['catimages']['folder'].$cat_image_name); $ImageFunctions->Resize(109,72); $ImageFunctions->RawOutput(); WriteFile($cfg['catimages']['folder'].$cat_image_name, $ImageFunctions->Output['Content']); $cat_image = $cat_image_name; $cat_slug = Word2Slug($cat_name); $Query = "INSERT INTO `product_cats` (`cat_name`,`cat_slug`,`cat_image`,`cat_description`) VALUES('$cat_name','$cat_slug','$cat_image','$cat_description')"; $Db->Query($Query); echo '<p>"'.$cat_name.'" Added.</p>'; } } ?> <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post" enctype="multipart/form-data"> <input type="hidden" name="action" value="add_cat" /> <p>Category Name: <input type="text" name="cat_name" /></p> <p>Category Image (Jpeg Only): <input type="file" name="cat_image" /> <p>Category Description:</p> <p><textarea name="cat_description" style="width:500px;height:250px;font-family:Arial, Helvetica, sans-serif;"></textarea></p> <p><input type="submit" value="Add Category" /></p> </form> Function is: //Write File function WriteFile($File, $Data){ $handle = fopen($File, 'w'); fwrite($handle, $Data); fclose($handle); } Any ideas? Thanks in advance, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/143660-fopen-permission-denied-error/ Share on other sites More sharing options...
Michdd Posted February 3, 2009 Share Posted February 3, 2009 CHMOD the file as well. Quote Link to comment https://forums.phpfreaks.com/topic/143660-fopen-permission-denied-error/#findComment-753775 Share on other sites More sharing options...
Mutley Posted February 3, 2009 Author Share Posted February 3, 2009 How do you CHMOD a file when you upload it? I don't understand why that would make any difference, since the directory is already 777. Quote Link to comment https://forums.phpfreaks.com/topic/143660-fopen-permission-denied-error/#findComment-753807 Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 chmod The directory just allows files to be written to it. The actual file has it's own set of permissions. The file would also need to be writeable, so 0667 I believe should suffice. Quote Link to comment https://forums.phpfreaks.com/topic/143660-fopen-permission-denied-error/#findComment-753815 Share on other sites More sharing options...
Mutley Posted February 4, 2009 Author Share Posted February 4, 2009 Where would I add it? To the function like this: function WriteFile($File, $Data){ chmod($File,0667); $handle = fopen($File, 'w'); fwrite($handle, $Data); fclose($handle); } Or is that in the wrong place? Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/143660-fopen-permission-denied-error/#findComment-754644 Share on other sites More sharing options...
premiso Posted February 4, 2009 Share Posted February 4, 2009 Did you try it? That looks like the right place to me. Quote Link to comment https://forums.phpfreaks.com/topic/143660-fopen-permission-denied-error/#findComment-754766 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.