-1

I am trying to store PDF generated by tcpdf in "uploaded_files" but getting error. I checked existing answers but they have path inside webroot. In my situation path is above root.

$pdf->Output("../../uploaded_files/".'Temp.pdf', 'F'); 

Message: fopen(): remote host file access not supported

Following are path details:

Web Root Path:/var/www/html/index.php
Upload Folder Path: /var/uploaded_files/

Permissions for both directories & files are 0777

Community
  • 1
  • 1
MyO
  • 413
  • 1
  • 8
  • 19

2 Answers2

1

The issue is related to file/directory permissions. Just for checking purposes make the access level of /var/uploaded_files to 777 and change owner to apache user of the directory /var/uploaded_files and then try to save file. If succeeds then adjust the permission as per your requirements. I suggest not to go with this approach because allowing Apache to access file system other than webroot is actually pretty dangerous.

codvlpr
  • 122
  • 4
  • I have already checked permissions, there is no permissions issue. I am using this approach to keep users files in safe place. I didnot find anyother solution for files safe keeping. – MyO Mar 25 '17 at 08:13
  • Did you go through the ownership of that folder? And what you can do is to use .htaccess to restrict the access of those user's files within the webroot. – codvlpr Mar 25 '17 at 08:24
  • Yes I can upload & delete files in these folders. .htaccess only prevents directory listing. When a file is rendered & user can get path of that file he can access that file so .htaccess is useless in this regard. – MyO Mar 25 '17 at 08:29
  • Can you run `ls -lh`in /var and paste the output? – codvlpr Mar 25 '17 at 08:31
  • 1
    @MyO apache runs php as a child process. That means that php only has permissions to those in group `http`. There is actually no other explanation. @codvlpr gave the correct answer. If you run php script from terminal, you can see that you can upload file anywhere. This is not a php question but more of apache and directory permissions – georoot Mar 25 '17 at 08:45
1

You need to use absolute file paths not relative file paths. Try something like

$pdf->Output("/var/uploaded_files/".'Temp.pdf', 'F'); 

Or

$pdf->Output(__DIR__ . "../../uploaded_files/".'Temp.pdf', 'F'); 
Eborbob
  • 1,905
  • 1
  • 15
  • 30