1

When using move_uploaded_file() I am trying to dynamically find the path to a img folder so that I can have the command working on both my local development server (XAMPP) and my remote production server. This is currently the function that I am using.

public function storePicture(): bool
    {
        $this->setNewPath('C:\fakepath\_img\uploads\\' . $this->getName());
        if (move_uploaded_file($this->getTmpName(), $this->getNewPath())) {
            return true;
        } else {
            return false;
        }
    }

Please note the \ is just to escape out that slash and really isn't important to look at because IT WORKS on my development server. I have tired using dirname() and it seems to be ALMOST working, except that it has reversed slashes and only gets the path from the root of the server directory. That probably will work on my production server but not on my development server apparently.

Tyler Lazenby
  • 409
  • 5
  • 27
  • You can move relatively from the current path in your application. Use Magic constants like `__DIR__` etc. And also check here https://stackoverflow.com/questions/4178263/make-a-path-work-both-on-linux-and-windows – codisfy Sep 19 '18 at 23:07
  • PHP is able to handle forward-slashes on Windows filesystems just fine. Don't worry about them. You can use `__DIR__ . '/some/relative/path'` on any operating system – Phil Sep 19 '18 at 23:07
  • @codisfy `__DIR__` / `dirname()`, same thing – Phil Sep 19 '18 at 23:08
  • @Phil oops I missed that part in the question. But yes, I just wanted to say that instead of hardcoding the path, just use relative paths from the application. – codisfy Sep 19 '18 at 23:10

0 Answers0