-1

I have a site where users need to log in before filling a form and their uploaded pic should be sent to the uploadfolder. i am working on wampserver on window. When i want to move the file to the folder, but i am getting this error: failed to open stream: Permission denied. Here is my code:

if (array_key_exists('terminervente', $_POST)) {
    // define constant for upload folder
define('UPLOAD_DIR', 'D:/wamp/www/projet-fembuleuse/upload_test/');
$file = str_replace(' ', '_', $_FILES['image']['name']);
if (empty($_POST['articlename'])) {
    $error[] = "Enter article name";
  }
     else{
        $name = htmlspecialchars(trim($_POST['articlename']));
     }

if (empty($error)) {
try {

  if ($pdo) {

   $sql = "INSERT INTO userarticles(id_user,name) VALUES(:id_user,:name);
$stmt = $pdo->prepare($sql);
$stmt->bindValue(":id_user", $id_user);
$stmt->bindValue(":name", $name);
if ($count > 0) {
   $success = move_uploaded_file( $_FILES['image']['tmp_name'],UPLOAD_DIR.$now.$file );

  if (!$success) {
    $error[] = "File could not be moved";
  }
    else{
   header('Location: '.HOMEACCOUNT);
      exit();
 }

   }

}//end try
  catch (PDOException $e) {
    $error[] = "Eror in scrip".$e->getMessage();
  }

So how i should make my uploadfolder writable to move the users pictures there? when i try to upload pic to the folder as the administrator..it works fine...but when i put a login form and i entered some login details of fictional users i have inserted in my db.. so that i can login and fill the form before uploading file and move to folder..it does not work...it is like only the administrateur can move file to the upload folder...

  • Possible duplicate of [move\_uploaded\_file gives "failed to open stream: Permission denied " error after all configurations i did](http://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error-after) – XCS Mar 12 '17 at 22:50
  • @Cristy: sorry for the duplicate.but i made research on internet before posting...the solution proposed did not work. – Afrik Developeur Mar 12 '17 at 23:19

1 Answers1

0

Your user doesn't have access to your server-side so they will never be able to directly write a file.

Permission is denied because the folder you are trying to write to does not have write permissions. Try to CHMOD that folder to 0777 and it should work.

If you are using a shared hosting here is how you can manually CHMOD a file: http://support.hostgator.com/articles/cpanel/how-to-change-permissions-chmod-of-a-file

XCS
  • 27,244
  • 26
  • 101
  • 151
  • when i use the chmod,0777..i get an error...here - it is chmod(): No such file or directory - any idea?? – Afrik Developeur Mar 12 '17 at 23:01
  • Yes, windows doesn't have `chmod`. Try this? http://stackoverflow.com/questions/23893823/file-puts-content-permission-denied-on-windows-7-wamp – XCS Mar 13 '17 at 11:13