Search code examples
iossafarimobile-safari

iOS Safari automatically save downloaded image


I am working on a website where a png image is downloaded from a php script. By sending headers we force the image to download in most browsers.

In iOS the image opens in the browser tab taking the user away from the UI and forcing them to manually long click and choose "Save Image" to save the downloaded image in their Camera Roll.

The download script sends headers like these:

<?php
$fileName="image.png";
$filePath="/somepath/".$fileName;

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$fileName.'"');
header('Content-length: ' . filesize($filePath));

readfile($filePath);
exit;

I am wondering if there are any headers I can send that would cause mobile safari on iOS to send the image straight to the camera roll without extra user actions or if there is a JS api that would allow pushing of images into the Camera Roll.

I realise this may not be possible as ios apps to not access the filesystem directly the way other platforms allow and have looked at similar questions:

I am just hoping there might be something specific to images to cause safari to send an image to Photos or the Camera Roll rather than viewing it in Safari.


Solution

  • Safari doesn't access the filesystem except through user interaction, which means that the long press is the only way to get it into the Camera Roll. It's part of the sandboxing paradigm.

    There isn't any equivalent of a "Downloads" directory.