filesize() returning false in php

Course Queries Syllabus Queries 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


i'm trying to make a jason of the files and there size, its working perfectly for the directory that this php file is saved in but when i change the directory the filesize() returns false. this works fine:

php
  header('Content-Type: application/json');
  $dir= "./"; //path
  $com/tag/list">list = array(); //main array

if(is_dir($dir)){
   if($dh = opendir($dir)){
       while(($file = readdir($dh)) != false){

           if($file == "." or $file == ".."){
               //...
           } else { //create object with two fields
               $com/tag/list">list3 = array(
               'file' => $file, 
               'size' => com/tag/files">filesize($file));
               array_push($com/tag/list">list, $com/tag/list">list3);
           }
       }
   }

   $return_array = array('com/tag/files">files'=> $com/tag/list">list);
   com/tag/echo">echo json_encode($return_array);
}
?>

but this doesn't work:

php
 header('Content-Type: application/json');
  $dir= "Syllabus/Undergraduate Courses/BCA/Semester 1"; //path
  $com/tag/list">list = array(); //main array

if(is_dir($dir)){
   if($dh = opendir($dir)){
       while(($file = readdir($dh)) != false){

           if($file == "." or $file == ".."){
               //...
           } else { //create object with two fields
               $com/tag/list">list3 = array(
               'file' => $file, 
               'size' => com/tag/files">filesize($file));
               array_push($com/tag/list">list, $com/tag/list">list3);
           }
       }
   }

   $return_array = array('com/tag/files">files'=> $com/tag/list">list);
   com/tag/echo">echo json_encode($return_array);
}
?>

error message: 
Warning: filesize(): stat failed for Communicat_GeneralEnglish1stSemsterCopyCopy2Copy.pdf in C:\xampp\htdocs\college\com/tag/list">listFiles.php on line 17

Warning: filesize(): stat failed for Environmental Studies_AECC-Environment-Studies-BCA.pdf in C:\xampp\htdocs\college\com/tag/list">listFiles.php on line 17

Warning: filesize(): stat failed for Foundation Course On Computers_B.CA_.pdf in C:\xampp\htdocs\college\com/tag/list">listFiles.php on line 17

Warning: filesize(): stat failed for Fundamentals Of Mathematics_B.CA_.3.pdf in C:\xampp\htdocs\college\com/tag/list">listFiles.php on line 17

Warning: filesize(): stat failed for Problem Solving And Programming With C_B.CA_.2.pdf in C:\xampp\htdocs\college\com/tag/list">listFiles.php on line 17
{"files":[{"file":"Communicat_GeneralEnglish1stSemsterCopyCopy2Copy.pdf","size":"0 bytes"},{"file":"Environmental Studies_AECC-Environment-Studies-BCA.pdf","size":"0 bytes"},{"file":"Foundation Course On Computers_B.CA_.pdf","size":"0 bytes"},{"file":"Fundamentals Of Mathematics_B.CA_.3.pdf","size":"0 bytes"},{"file":"Problem Solving And Programming With C_B.CA_.2.pdf","size":"0 bytes"}]}

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.