php require_once path difference between windows and linux

I have a file located in my CakePHP root folder placed under a folder named cron. Path is:

c:/wamp/www/project/cron/daily.php

This file requires another file placed inside vendor folder of cake structure, like this:

require("/../vendors/phpMailer/class.phpmailer.php");

And i run this daily.php from task scheduler. This is the scenario in my development site.(Windows system). It works fine as expected. When i migrated the project to Ubuntu(production site), the require statement started causing issues; it cant find the required file. I made a small change there, like this:

require("../vendors/phpMailer/class.phpmailer.php"); <= removed the preceding slash

And it worked. So my doubt is, is there a difference in how parent directory notation work in widows and Linux? If so, how can i overcome this? Its not feasible to remove a slash every time I move the project from my development site(windows) to production site (Linux).


I tried this:

 require("./../vendors/phpMailer/class.phpmailer.php");

It worked in linux. But gave "no such file directory" error in windows. It seems windows works only with:

 require("/../vendors/phpMailer/class.phpmailer.php");

Solution

From @TWCrap's help problem was solved as follows:

require(dirname(__FILE__)."/../vendors/phpMailer/class.phpmailer.php");

It works in both windows and linux(* tears of joy *). But in windows it produces path as:

C:\wamp\www\project\cron/../vendors/phpMailer/class.phpmailer.php

This path looks ugly and i hope it wont cause probs in future!

-Thanks guys!

Answers


AS i remember, when you put 1 dot infront of the line, you start at the directory you are. So then the line must look like this:

require("./../vendors/phpMailer/class.phpmailer.php");

And that should work at windows and linux....


Need Your Help

Admobs sometimes appear twice on different locations

objective-c ios cocoa-touch admob iad

We are adding admobs as a backup ad-system for countries without iAd. But sometimes the ads appear twice, the second ad sometimes in the middle of the screen about 100-200 px above the other ad. It...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.