Home >Backend Development >PHP Tutorial >I use file_put_contents to upload an image, but it can only be saved in the current directory. How can I move the image to the desired directory?

I use file_put_contents to upload an image, but it can only be saved in the current directory. How can I move the image to the desired directory?

WBOY
WBOYOriginal
2016-10-10 11:39:131513browse
<code>$id = $_POST['id'];
$name = $_POST['name'];
$address = $_POST['address'];
$phonenumber = $_POST['phonenumber'];
$image = $_POST['image'];//得到图片
$imageBase64 = base64_decode($image);

$host = $_SERVER['HTTP_HOST'];//获取主机IP
$post = $_SERVER['HTTP_PORT'];//获取主机端口


$imageName = $id.".png";//生成的图片名称和用户ID一样
$file_put = file_put_contents($imageName, $imageBase64);

</code>

I uploaded the image after converting it to Base64, but using the file_put_contents function can only be placed in the directory of the script. How can I move the uploaded image to the desired directory?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn