Warning: fread () [function.fread]: length parameter must be greater than 0

I have a site with 1and1 - who is useless! For some reason, the backup scripts that they provide no longer work, and they cannot provide me with an answer! So I decided to write my own, this is my code:

  if (file_exists('backupfile.sql')){

 $FP = fopen ( 'backupfile.sql', 'r' );
 $READ = fread ( $FP, filesize ( 'backupfile.sql') );
 $READ = explode ( ";\n", $READ );

 foreach ( $READ AS $RED )
 {
  mysql_query ( $RED );
 }

  echo 'Done'; 
 }else{
  echo "no file";
 }

however this gives me the following error

Warning: fread() [function.fread]: Length parameter must be greater than 0 

if I put @infront in fread, the script does not raise an error, but does not back up.

+3
source share
3 answers

Well ... My guess from the error message was that it was backupfile.sqlempty. Therefore, fread()can not read any of it.

+3
source
filesize ( 'backupfile.sql')

, , , PHP .

edit: is_readable(), ,

+1

you must specify the maximum read size when using fread. this indicates that it thinks your file size is 0. try using FILE because it is a local file and that’s it ...

if (file_exists('backupfile.sql')){

 $READ = file( 'backupfile.sql');

 foreach ( $READ AS $RED )
 {
  mysql_query ( $RED );
 }

  echo 'Done'; 
 }else{
  echo "no file";
 }
+1
source

Source: https://habr.com/ru/post/1775853/


All Articles