1

I've been on this bug for too long so I'm looking for some help from more experienced server programmers.

I'm running a Bitnami LAMP stack. I'm trying to use a PHP script (maintenance.php) to move files on the server. So I'm using rename(filepath, newpath) in my script. However, the PHP script cannot find the file even though it exists on the server.

SOLVED: The problem was that I was calling the script from two different places during debug (my browser, and my linux shell). The "working directory" in each of these places was different so the filepaths represented different locations depending on where I called the PHP script from.

wmcnally
  • 147
  • 2
  • 14

1 Answers1

1

There is no pictures directory at root so /pictures wont work. Instead you will have to use absolute path to the pictures directory.

There are multiple ways to do this.

You can use $_SERVER['DOCUMENT_ROOT'] which will give you root directory under which the current script is executing.

reserved.variables.server

Also, you can use __FILE__ which will give you the path to current file. With dirname(__FILE__) you can get directory and then you can work up to the pictures directory by going level down using ../.

This is also a similar question that you can check,

PHP include absolute path

Community
  • 1
  • 1
vaibhavmande
  • 1,115
  • 9
  • 17
  • I'm making progress now. I was majorly confused because I was running the php script from my browser as well as the shell and the working directories were different for each. Thanks for your help. – wmcnally Nov 14 '15 at 05:43