简体   繁体   中英

zend framework 2 How do i link a file in the controller (What is the path)

How do I link a file in the controller

$OpenuUserPersonalFile = fopen("/ZendEbayApp/data/usersinformationin/userPersonal.txt", "r");

echo fgets($OpenuUserPersonalFile) . "<br />";

fclose($OpenuUserPersonalFile);

Would this be corrent?

Here is how i link a file in my layout /ZendEbayApp/public/css/MainPageLayout.css

This is where my controller is: \\ZendEbayApp\\module\\Application\\src\\Application\\Controller

Assuming you're using the ZF2 Skeleton application, you'll notice that public/index.php contains a line like:

chdir(dirname(__DIR__));

That's changes the directory to the root of your project.

So to reference the file in your example, you'd simply do:

$fp = fopen('data/usersinformationin/file.txt', 'r');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM