skip to Main Content

I am doing a file upload page , that will rename the file before adding it , and i am getting those errors.
I’ve tried chmod -R 777 ./ in the folder of the website but it still doesn’t work.

 $dir = Users::currentUser()->id;//each user have his folder
if(move_uploaded_file($_FILES["file"]["tmp_name"], PROOT . 'files' . DS . $dir . DS))
    {
      echo "The file has been uploaded as ".$ran2.$ext;
        //Router::redirect('upload');
    }
    else
    {
      echo "Sorry, there was a problem uploading your file.";
    }

The PROOT is defined by me as the website root folder define('PROOT','/framework/'); and the DS is the separator (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR);.

And this is how the error looks

Warning: move_uploaded_file(/framework/files/4/): failed to open stream: No such file or directory in /opt/lampp/htdocs/framework/app/controllers/UploadController.php on line 46


Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpHz70FG' to '/framework/files/4/' in /opt/lampp/htdocs/framework/app/controllers/UploadController.php on line 46

And i am also getting the error from the if statement

Sorry, there was a problem uploading your file.

And here is a picture of my files structure

Update

The problem were cause of ubuntu permissions , on windows it works perfect

2

Answers


  1. try it

    define('PROOT','framework/');
    (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? define('DS', '/') : define('DS', DIRECTORY_SEPARATOR)
    
    $dir = Users::currentUser()->id;//each user have his folder
    $path = PROOT . 'files' . DS . $dir . DS;
    if(move_uploaded_file($_FILES["file"]["tmp_name"],$path)
        {
          echo "The file has been uploaded as ".$ran2.$ext;
            //Router::redirect('upload');
        }
        else
        {
          echo "Sorry, there was a problem uploading your file.";
        }
    
    Login or Signup to reply.
  2. you have to use absolute path
    like

     define('PROOT','/opt/lampp/htdocs/framework/');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search