2017-05-04 23:31
浏览 78


I need to check if http://localhost/filname.php exists. I have to use localhost so that the server checks for the file itself instead of going out to the proxy to look for the file.

If the file exists in the directory:

  • if(file_exists($hostname_url)) resolves to false
  • curl successfully gets the file and prints out the contents I expect.
  • wget gets the file

If the file doesn't exist:

  • if(file_exists($hostname_url)) resolves to false.
  • curl attempts to get the headers to see if the file exists never ends and spawns until apache chokes.
  • curl attempts to get the file never fails and spawns until apache chokes
  • wget sits forever waiting for response

I need a way to check if the file exists and only act if it does and I am stuck. I am working on a drupal site so I have no idea if the problem is just php, or php + drupal situation

图片转代码服务由CSDN问答提供 功能建议

我需要检查 http://localhost/filname.php 存在。 我必须使用localhost,以便服务器检查文件本身,而不是去代理查找文件。


  • if(file_exists($ hostname_url))解析为false
  • curl成功获取文件并打印出我期望的内容。 \ n
  • wget获取文件


    • if (file_exists($ hostname_url))解析为false。
    • curl尝试获取标题以查看文件是否存在永远不会结束并生成直到apache chokes。
    • curl 尝试获取文件永远不会失败并产生直到apache chokes
    • wget永远等待响应

      我需要一种方法来检查 如果该文件存在,只有这样做,我就被卡住了。 我正在一个drupal网站上工作所以我不知道问题只是php,还是php + drupal情况

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doupa9062 2017-05-05 08:29

    Your way is correct, just use DRUPAL_ROOT:

    file_exists(DRUPAL_ROOT . '/filename.php')

    DRUPAL_ROOT is local drupal destination path, example:

    解决 无用
    打赏 举报