亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

返回相對于站點根目錄的路徑,而不是服務器根目錄

返回相對于站點根目錄的路徑,而不是服務器根目錄

PHP
catspeake 2021-10-22 16:59:36
為什么?我需要檢測給定的路徑是否包含目錄,app但僅在站點的根目錄之后(即忽略完整的服務器路徑,只搜索實際站點內的路徑)。考慮以下路徑:/root/var/www/app/app/Http 真的/root/var/www/app/public 錯誤的C:\Users\john\Sites\example_com\www\app\Http 真的我嘗試過的...我已經使用以下代碼解決了上述問題:// Normalise the directory separators in the document// root$document_root = str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']);// Remove the '/public' path from the end, this should // give us the path to the site root...$site_root = str_replace(DIRECTORY_SEPARATOR . 'public', '', $document_root);// Normalise the directory separators in the supplied// path$normalised_path = str_replace('/', DIRECTORY_SEPARATOR, $path['path']);// Remove the site root from the beginning of the path$stripped_path = str_replace($site_root, '', $normalised_path);// Now we can run our tests...我的問題是我還是上面的代碼對于這樣一個簡單的任務來說似乎很荒謬?任何人都可以提出更好或更清潔的方法來實現這一目標嗎?本質上,我試圖從給定的路徑中剝離服務器根目錄,以便為我提供一個相對于站點根目錄的路徑......如果有一種方法可以使用 Laravel/Lumen 中的內置類/方法來實現這一點,那么也請隨時提出這些建議。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號