Read a file in a subdirectory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lolyzor
    New Member
    • Dec 2012
    • 3

    Read a file in a subdirectory

    Code:
    $fileContent = file_get_contents('upload/'.$assId.'/'.$matric.'.cpp');
    file_put_contents('filename.txt',$fileContent);
    I'm trying to read a file which I created in another php script, the file exists on that path, I checked the parameters $assId and $matric they are correct, and the file is not empty it has simple sentence in it, i tried fread as well but im getting empty string as result.

    I'm using windows (so no issues regarding permissions I guess), and I am issuing ajax call to this php script which will read the file and return back json encode contents of the file so I can display it from calling php script.

    So are there any secret tips and tricks in reading files from sub-directories? I also tried absolute path with dirname(__FILE_ _) then append /upload/ that did not work as well.
    Last edited by Stewart Ross; Dec 9 '12, 07:24 PM. Reason: removed filename which broke site rules - please do not post code with 'jokey' swear words such as 'fuckme.txt' as file names
  • lolyzor
    New Member
    • Dec 2012
    • 3

    #2
    I did manage to solve the problem, actually the file did not exist, because I was using int to store to database when I retrieve it, 0823369 will be 823369, but when I store something for the name I use string so the file on the disk is 0823369, file name from the database was 823369, yeah I'm stupid.

    Comment

    Working...