tags:

views:

35

answers:

3

works fine on the desktop with xampp but when i upload it to my webhost it doesnt. The file x.csv is in the same dir

$csv_file = "x.csv";

$handle = fopen(($csv_file), "r");

the error i get is-

fopen(x.csv): failed to open stream: No such file or directory in /var/www/html/x/admin/import_one.php on line 12

Where am I going wrong?

A: 

Linux is case-sensitive, Windows isn't.

Make sure that your file is called x.csv and not X.csv or x.CSV.

Andrew Moore
+1  A: 

check that you have reading permissions for x.csv also try

$handle = fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . $csv_file, 'r'); 
(maybe your cwd isn't in the same directory)

matei
_FILE_ being? the filename of the csv file? or import_one.php?
chris
my bad.. cheers.. sorted
chris
`__FILE__` is a [magic constant](http://php.net/constants.predefined) that always resolves to the path of the current file, so `dirname(__FILE__)` means "directory of the current script."
Adam Backstrom
A: 

When in doubt use absolute file path.

$path = '/path/dir/something/';
$file = 'x.csv';

$fp = fopen($path . $file, 'r');
if ($fp)
{ 
    // do some amazing stuff here.
}
capfu