我有一個使用GD Lib生成圖像的php腳本,將它保存到預定義的位置。然後輸出它。PHP保存並輸出GD Lib圖像 - 相對和絕對路徑
我的目錄結構是這樣的:
www.example.com/projects/project-1/
裏面的項目1目錄我有以下目錄:
- /imgs/
- /js/
- /css/
- /php/
使用GD庫的腳本是在/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/
那麼,什麼是最優雅的解決了這個問題?