0
我已經開始學習PHP。我在許多文件中使用文件路徑。我希望使用它在配置文件中定義並在所有需要的文件中使用該變量。目前我在下面的文件中使用過它。從配置文件到其他文件的變量
function base64ToImageProfile($base64_code){
$img_base64 = $base64_code;
//replace data:image/jpeg tag from base64
$img_base64 = str_replace('data:image/jpeg;base64,', '', $img_base64);
//replace data:image/png tag from base64
$img_base64 = str_replace('data:image/png;base64,', '', $img_base64);
//replace space with + from base64
$img_base64 = str_replace(' ', '+', $img_base64);
//decode base64 to image object
$decode_img = base64_decode($img_base64);
if (!$decode_img) {
return 'error';
}
//create path for image
$file_path= 'userImage/'.uniqid().'.png';
$success=file_put_contents($file_path,$decode_img);
//saves decoded image to specified path
if ($success) {
$file_path = 'www.example.com/myfolder/'.$file_path;
}
return $success ? $file_path:'error';
}
我想從配置文件中使用變量爲我的url位於它。我該怎麼做?
獲得從'$ _SERVER'這些信息如果你硬編碼你在每次上安裝代碼的時間來改變它新服務器 – RiggsFolly
@RiggsFolly這是很好的解決方案。你能告訴我如何在這一行中使用它嗎?「$ file_path ='www.example.com/myfolder/'.$file_path;」 ?謝謝 –
'$ HowToBecomeADeveloper =(試驗+測試)' – RiggsFolly