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?
<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?