douhao2011 2014-11-05 22:59
浏览 63
已采纳

PHP文件重命名自己

I'm attempting to write an upgrade script for one of our website. Currently the script will unzip files provided from the upgrade link and unzip to the directory.

My problem is if there is a new version of itself i.e. upgrader-new.php I need the script to run to completion and then delete itself, then haveupgrader-new.php be renamed to upgrader.php.

The only solution I can think of would be to create a third file i.e. upgrade-assist.php that would be run before any upgrade to check if upgrader-new.php exists and if it does, delete the original and rename the new to the proper name. I forsee problems because the original script would still have to call upgrader-assist.php and as far as I know you can't delete a running script?

Any suggestions?

Thanks!

  • 写回答

1条回答 默认 最新

  • dony39517 2014-11-05 23:05
    关注

    as far as I know you can't delete a running script?

    You can, try this one:

    <?php unlink(__FILE__);
    

    It is perfectly fine, unless there are other processes using this file (and of course running process has enough permission to do so).

    File is not processed and executed line by line, but loaded into memory so you can freely rename or delete it, and it will still run until the end (or fatal error).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?