chris
chris

Reputation: 8689

php file error. silly small problem

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?

Upvotes: 0

Views: 74

Answers (3)

capfu
capfu

Reputation: 157

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.
}

Upvotes: 0

matei
matei

Reputation: 8685

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)

Upvotes: 1

Andrew Moore
Andrew Moore

Reputation: 95344

Linux is case-sensitive, Windows isn't.

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

Upvotes: 0

Related Questions