<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?
<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?
The first parameter filename of file_put_contents can take a path, so you only need to modify the $imageName variable to the directory and file name you want to move, similar to the following code:
<code>file_put_contents("../static/images/1.png", $imageBase64);</code>
Get familiar with the manual first https://secure.php.net/manual...
The saved path can be spliced, so you can splice it into the path you want to upload, or it can be an absolute path