Search code examples
phpfileuploadheadercontent-disposition

Upload file in Content Disposition


what's up

I'm trying to upload a file in Content Disposition.

I have a website who link 2 images with PHP. So, I have an image on my server and then I upload another image (Transparent with some objects for example), then I have a new image created with this code:

imagecopymerge($src, $dest, 0, 0, 0, 0, 600, 600, 45);
header('Content-Disposition: Attachment; filename="flagperfil.png"');
header('Content-Type: image/png');
imagepng($src);
imagedestroy($dest);
imagedestroy($src);

It works, is PHP. But now, this image doesn't have a direct link, is only a php file who have this new image.

How can I upload this new image to my website?

Regards


Solution

  • If you want to save the image, pass the second parameter as the file path/name where to save. Below code will save the image to where your script executed. For example, if your script runing on www.example.com/image/script.php with below code your image will be saved to www.example.com/image/file.png

        imagepng($src, "file.png"); 
    

    If you want to save your image to other directory, give it to full path and name:

       imagepng($src, "/var/www/html/images/file.png"); 
    

    See this: http://php.net/manual/en/function.imagepng.php#102944