dongxi1965 2016-01-04 20:39
浏览 16
已采纳

执行位于另一个文件夹中的PHP文件

I have a script that uploads a file. It then creates a new folder and moves the uploaded file to that folder along with the another script.

After the file is moved, I need to run a second script that resides in the new folder. But I need the second script to use its path and NOT the path of where it is called/executed from. (the upload script)

This is how I have tried to execute the script from the upload script.

exec("php-cli uploads/".$dirname."/".$file_name."/generate_thumbs.php");

I have error reporting on but nothing is generated. Any ideas?

  • 写回答

2条回答 默认 最新

  • dqyp50298 2016-01-04 20:50
    关注

    If you want to change working directory, use chdir() before exec(). You can pass either absolute or relative directory name. To execute PHP from PHP you can use include instead of exec().

    edit your upload script to:

    <?php
        // ... upload the file ...
    
        // ,,open'' the target directory
        chdir("uploads/$dirname/$file_name/");
    
        // start the thumbs script
        // this filename is relative to "uploads/$dirname/$file_name/"
        include "generate_thumbs.php";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路