Reputation: 61
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
Upvotes: 3
Views: 29929
Reputation: 81
Use file_put_contents();
$image = file_get_contents('http://www.blahblahblah.com/logo.gif');
file_put_contents('./myDir/myFile.gif', $image);
Upvotes: 6
Reputation: 964
$File
is your path and filename, you can change folder from it (http://www.php.net/manual/en/function.fopen.php).
Upvotes: 0
Reputation: 1681
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 =).
Upvotes: 4