文件不存在于路由Http目录laravel 5中


file doesnt exists in routes Http directory laravel 5

我在routes.php旁边有一个python脚本,我想从routes.php文件中执行它。当我使用exec()函数时,它不能正常工作。所以,我尝试file_exists():

Route::get('/py', function(){
    if (file_exists( "new.py" ))
        echo "succeed";
    else
        echo "failed";
});

它只返回failed,那么我如何通过exec函数从.py文件中获得输出呢?

您需要使用绝对路径,请尝试使用

 file_exists(__DIR__.'/new.py')

假设它与routes.php 在同一目录中

您提供的文件路径不正确file_exists()将检查laravel中public文件夹内的文件。如果您将py放置在公用文件夹中,请给出该文件的确切路径。