can't create files in typo3 inside fileadmin

908 views Asked by At

I am building an extension with extbase where I need to create a pdf file inside fileadmin folder with php from a controller :

fopen("/fileadmin/pdf/anass.pdf", "w") or die('could not create file');

The permission is granted to write files ... so I think I made a mistake writing the path. Could somebody please help me?

PS: I am working on typo3 4.5

1

There are 1 answers

0
biesior On BEST ANSWER

Indeed you're specifying absolute path in the filesystem and most probably there's no such path like /fileadmin/pdf/... there.

Quite safe would be using some TYPO3 constant to specify where's your app's root i.e. PATH_site, like:

  fopen(PATH_site . "/fileadmin/pdf/anass.pdf", "w") or die('could not create file');

it will use the path like (sample)

/var/www/your-app/fileadmin/pdf/anass.pdf

note, that if you should use slash before fileadmin or not is OS/server config depended, so just check if your PATH_site ends with slash or not.