tecmeister Posted May 13, 2009 Share Posted May 13, 2009 Hi every one, I have been creating a form to upload data and images for a news page. But it seems to be having a problem moving the image to the folder that I have select. Warning: move_uploaded_file(me.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/cxgsyste/public_html/test/add.php on line 30 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpJSOKwU' to 'me.png' in /home/cxgsyste/public_html/test/add.php on line 30 Here is the script. <form action="<?php $_SERVER['PHP_SELF']. '?insert_tech_news=' ?>" enctype="multipart/form-data" method="post"> Title:<br /> <input type="text" name="title" style=" width: 99%" /> <br /><br /> Info:<br /> <textarea name="info" rows="10" cols="80"></textarea> <br /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> Upload Image:<br /> <input type="file" name="userfile" /> <br /><br /> <input type="submit" value="Add Tech News" name="tech" /> </form> <?php if(isset($_POST['tech'])){ $title = $_POST['title']; $info = $_POST['info']; $date = date("L jS F Y h:i:s"); $upload_dir = "new_tech/"; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if(!result){ echo "Upload Error"; exit(); } if(!get_magic_quotes_gpc()){ $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "INSERT INTO tech(title, info, date, name, size, type, path) VALUES ('$title','$info','$date','$fileName','$fileSize','$fileType','$filePath')"; $result = mysql_query($query)or die(mysql_error()); } ?> Thanks for your help, tecmeister. Quote Link to comment https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/ Share on other sites More sharing options...
JonnoTheDev Posted May 13, 2009 Share Posted May 13, 2009 Have you set write permissions on the directory where the files will be moved to? Quote Link to comment https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/#findComment-833148 Share on other sites More sharing options...
tecmeister Posted May 13, 2009 Author Share Posted May 13, 2009 Sorry I have just learnt that off a tutorial. It worked on the WAMP server. But When I put if on to a web server it came up with that warning. Please will you be able to point me in the right direct of what I sould be doing. Thanks for your help Neil, tecmeister. Quote Link to comment https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/#findComment-833159 Share on other sites More sharing options...
JonnoTheDev Posted May 13, 2009 Share Posted May 13, 2009 You need to change the directory permissions on the folder where the files are saved to i.e. new_tech/ (as in your script). Allow write permissions 777 Quote Link to comment https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/#findComment-833160 Share on other sites More sharing options...
tecmeister Posted May 13, 2009 Author Share Posted May 13, 2009 Hi Neil, i have change the permission of the directory but it is still iving me the same warning. Is there something that I have missed? Quote Link to comment https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/#findComment-833301 Share on other sites More sharing options...
JonnoTheDev Posted May 13, 2009 Share Posted May 13, 2009 As your error clearly states: failed to open stream: Permission denied Either you have not set the path to the folder correctly in the script, the folder has the wrong ownership i.e it should not be owned by root, and or the permissions on the folder are incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/#findComment-833305 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.