[英]Uploading a base64 image as an image file
因此,我正在接收base64編碼的圖像。 我想解碼圖像並將其上傳到特定目錄。 編碼的文件是圖像,我正在使用$file = base64_decode($base64_string);
對其進行解碼。 通過file_put_contents('/uploads/images/', $file);
總是導致failed to open stream: No such file or directory
錯誤。
那么,如何獲取解碼后的字符串並將其上傳到特定路徑?
謝謝。
您的路線是錯誤的。
/uploads/images
正在/目錄中查找名為uploads的文件夾。 您應該指定文件夾的完整路徑:
/var/www/vhosts/MYSITE/uploads/images
我遇到了同樣的問題,並最終解決了這個問題:
<?php
$file = base64_decode($base);
$photo = imagecreatefromstring($file);
//create a random name
$RandomStr = md5(microtime());
$name = substr($RandomStr, 0, 3);
$name .= date('Y-m-d');
$name .= '.jpg';
//assign name and upload your image
imagejpeg($photo, 'images/'.$name, 100);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.