【发布时间】:2015-08-26 04:59:18
【问题描述】:
我有一个 php 脚本,它使用 GD Lib 生成图像,并将其保存到预定义的位置。然后应该输出它。
我的目录结构是这样的:
www.example.com/projects/project-1/
在 project-1 目录中,我有这些目录:
- /imgs/
- /js/
- /css/
- /php/
使用 GD Lib 的脚本位于 /php/ 中,其中定义了常量的另一个 config.php 脚本。然后将其包含在主脚本中。
假设我有两个常量:
define('SAVE_PATH', '/projects/project-1/imgs/'); //The image will not save - this does not work
define('OUTPUT_PATH', '/projects/project-1/imgs/'); //this works if there is an image in this location
然后我像这样保存图像:
imagejpeg($im, SAVE_PATH.$name, 100);
我收到以下错误:
failed to open stream: No such file or directory in /public_html/projects/project-1/php/main.php
是否有可能只使用一个既可用于保存又可用于输出的常量?
我知道我不能有绝对的保存路径,例如:http://www.example.com/projects/project-1/imgs/
而且我知道我不能有绝对输出路径,例如:/public_html/projects/project-1/imgs/
那么解决这个问题最优雅的方法是什么?
【问题讨论】:
标签: php gd relative-path filepath absolute-path