douzhang3898 2013-06-20 22:10
浏览 356
已采纳

如何使用php中的file_put_content从不同的路径(不是服务器默认路径)打开文件

Is there any way to file_put_contents from different path i mean instead of

c/programfiles/../../htdocs/test.txt using c/test/test.txt

the below is the code i am using:

$date=current_date;

$file = "test_"$date".txt";

$contents = "testtest";

file_put_contents($file, $contents);

Many thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongmijgnnq0118 2013-06-20 22:37
    关注

    When placing files on your computer you can either use relative or absolute path like this:

    // absolute path
    $file = "C:/temp/test.txt";
    
    // relative path from C:/Program Files/wamp/htdocs/index.php
    $file = "../../temp/test.txt";
    

    Both of those files point to the same place

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

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器