Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fopen() not working

Tags:

file

php

fopen

I'm want to read a simple string from a text file which is around 3-4 mb but fopen() fails ("can't open file" from die() is called). Here's the code:

clearstatcache();
$fh = fopen("/my/path/to/file.txt", "r") or die("can't open file");
$sql = fread($fh,filesize("/my/path/to/file.txt"));
like image 720
Tim Specht Avatar asked Feb 23 '23 01:02

Tim Specht


1 Answers

Have you firstly checked to see if the file exists?

if (!file_exists("/my/path/to/file.txt") { 
    die('File does not exist');
}

clearstatcache();

$fh = fopen("/my/path/to/file.txt", "r") or die("can't open file");
$sql = fread($fh,filesize("/my/path/to/file.txt"));
like image 134
pb149 Avatar answered Mar 04 '23 22:03

pb149