[英]Php save file to specific location?
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. 这将image.jpg保存到我的主题根文件夹中。 how to save it to server root folder ... /Public_html/wp-content/uploads ? 如何将其保存到服务器根文件夹... / 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(); 使用file_put_contents();
$image = file_get_contents('http://www.blahblahblah.com/logo.gif');
file_put_contents('./myDir/myFile.gif', $image);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.