Re: filesize question

From: Date: Wed, 08 May 2013 02:38:40 +0000
Subject: Re: filesize question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-321030@lists.php.net to get a copy of this message
On Tue, May 7, 2013 at 8:16 AM, Curtis Maurand <curtis@maurand.com> wrote: > Hello, > I'm feeding a filename to a php script on the command line (command line > program). I run the following against it: > > $inputline = fread($inputfile, filesize($argv[1])); > > I'm getting an error complaining that the second parameter can't be '0' The thing to look for, is how did you get $inputfile out of the command line, and why you'd expect the file name to be in $argv[1] at that point? Marco's suggestion isn't really going to work as $inputfile will be a file handle, and filesize() needs the name of the file. Maybe want to give us a wider look at what your code is doing? Generically, you can wrap this up as: function binread_file($filename) { $handle = fopen($filename,'rb'); if (FALSE === $handle) die("Unable to open $filename"); $contents = fread($handle, filesize($filename)); if (FALSE === $contents) die("Unable to read $filename"); return $contents; }

« previous php.general (#321030) next »