i have this
<?php
$canvasImg = $_POST['img'];
$data = base64_decode($canvasImg);
$File = $_POST['imgname'].jpg;
$Handle = fopen($File, 'w');
fwrite($Handle, $data);
fclose($Handle);
?>
this saves image.jpg to my theme root folder. how to save it to server root folder ... /Public_html/wp-content/uploads ?
thanks
Try this:
<?php
$link= $_POST['img'];
$destdir = '/public_html/wp-content/uploads';
$img=file_get_contents($link);
file_put_contents($destdir.substr($link,strrpos($link,'/')),$img);
?>
Let me know if it worked out for you =).
$File
是你的路径和文件名,你可以从中更改文件夹( http://www.php.net/manual/en/function.fopen.php )。
Use file_put_contents();
$image = file_get_contents('http://www.blahblahblah.com/logo.gif');
file_put_contents('./myDir/myFile.gif', $image);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.