Hello,

I am trying to fix my server file path. After moving my web project file from localhost to the server. There are several errors that appears. One of them is: Destination folder does not exist or no permissions to see it.

file_upload_exercise.php

define('DESTINATION_FOLDER','c://xampp/htdocs/squprime/administrator/admin/materialstorage/');

if (!@file_exists(DESTINATION_FOLDER)) {
      $errors[] = "Destination folder does not exist or no permissions to see it.";
      break;
    }

The same file works on localhost, I already check my file - it is correct! I wonder what I did wrong?

Recommended Answers

All 6 Replies

What is the server OS? If it is one of the Linux distros the path for html documents would not be the same as in Windows. A couple of examples:

/var/www/html
/var/www
/srv

So you might want to reference the web path which is not suppose to change and hardcode the rest or check for the OS: for the later you could use some info from the $_SERVER superglobal variable, maybe $_SERVER['SCRIPT_FILENAME'] or $_SERVER['SERVER_SOFTWARE'] but I don't know how reliable this is. Example:

// use this in Windows
define('BASE_PATH', 'c://xampp/htdocs/');
// use this in Ubuntu
define('BASE_PATH', '/var/www/html/')

define('DESTINATION_FOLDER', BASE_PATH . 'squprime/administrator/admin/materialstorage/');
Member Avatar for diafol

Were you seriously expecting the localhost and remote host paths to be the same?

The relevant SERVER vars

[DOCUMENT_ROOT] => C:/xampp/htdocs/myproject

[CONTEXT_DOCUMENT_ROOT] => C:/xampp/htdocs/myproject

[SCRIPT_FILENAME] => C:/xampp/htdocs/myproject/index.php

Server software gave me this:

 [SERVER_SOFTWARE] => Apache/2.4.9 (Win32) OpenSSL/1.0.1g PHP/5.5.11

Using magic constants:

__DIR__  = C:\xampp\htdocs\myproject

If you include a config.php file in all your pages. You could actually hard code the path to a CONSTANT.

The web server has Windows Server 2012 OS.

The $_SERVER['SCRIPT_FILENAME'] equal to: C:/xampp/htdocs/administrator/admin/file_upload_material.php

I still cannot get it right like it works just like in the localhost.

Is the server running IIS or XAMP? IIS has different document root path from XAMP as far as I know. XAMP is really only ment for local development.

I finally figure how to make it work - I have to type:

define('DESTINATION_FOLDER','materialstorage/');

Kool. Solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.