0

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?

3
Contributors
6
Replies
22
Views
2 Years
Discussion Span
Last Post by broj1
0

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/');

Edited by broj1

0

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.

Edited by diafol

0

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.

Edited by davy_yg

0

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.

Edited by broj1

0

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

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

Edited by davy_yg

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.