Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

filesize() returning false in php

Course Queries Syllabus Queries

Max. 2000 characters
Replies

usr_profile.png

User

( 4 months 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
  $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
               $list3 = array(
               'file' => $file, 
               'size' => filesize($file));
               array_push($list, $list3);
           }
       }
   }

   $return_array = array('files'=> $list);
   echo json_encode($return_array);
}
?>

but this doesn't work:

<?php
 header('Content-Type: application/json');
  $dir= "Syllabus/Undergraduate Courses/BCA/Semester 1"; //path
  $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
               $list3 = array(
               'file' => $file, 
               'size' => filesize($file));
               array_push($list, $list3);
           }
       }
   }

   $return_array = array('files'=> $list);
   echo json_encode($return_array);
}
?>

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

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

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

Warning: filesize(): stat failed for Fundamentals Of Mathematics_B.CA_.3.pdf in C:\xampp\htdocs\college\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\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"}]}

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif