2

I'm going crazy with this. Been looking here and at Google for a solution. The code I copied works fine under Android, but it does nothing when I try to run it on an iPhone 6. I read that it used to work on iPhone 5 at least, but seems that there is no way to force video download on iPhone 6 and 7.

Is there any way to force or ask for a file to be downloaded on an iPhone using PHP? There's something wrong with this code or is just a pain in the ass provided by Apple?

<?php
ob_start();

if(!empty($_GET['file'])) {

    $fileName = basename($_GET['file']);
    $fileName = getcwd() . '/uploads/videos/' . $fileName;

    header('Content-Description: File Transfer');
    header('Content-Type:  application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $fileName);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    ob_clean();
    flush();
    readfile($fileName);
    exit;
}
shim
  • 9,289
  • 12
  • 69
  • 108
DaNoiseMan
  • 139
  • 2
  • 13
  • 3
    Possible duplicate of [Using php to output an mp4 video](https://stackoverflow.com/questions/5924061/using-php-to-output-an-mp4-video) – ishegg Aug 24 '17 at 14:32
  • @ishegg, that post is old, from 2011, iPhone 6 were not released at that moment. That's the big difference. – DaNoiseMan Aug 24 '17 at 14:34
  • Have you actually tried the solution described by ishegg before dismissing it ? – nathan Aug 24 '17 at 14:41
  • @nathan , saw it before make this post, but it didn't work. – DaNoiseMan Aug 24 '17 at 14:45
  • 1
    You can't force download or ask in native Safari. The browser will always display a video element. As such the solution provided by the post linked above is correct (tested in an iPhone 6s with iOS 11 beta 5) – nathan Aug 24 '17 at 14:59
  • @nathan that should be the accepted answer ;) – brandonscript Aug 24 '17 at 15:12
  • Thanks brandon but it still feels like a dupe. I didn't actually provide any code or insight, just verification. – nathan Aug 24 '17 at 15:13
  • @nathan, the response from the browser it's just plain text, do you get something like this? ftypisomisomiso2avc1mp41free�mdat�����E���H��,� �#��x264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 ......�� – DaNoiseMan Aug 24 '17 at 15:31
  • It just print the content of the file under iPhone 6. Also, i tried to make an echo if the client accept http range ( 'if isset($_SERVER['HTTP_RANGE']))' ), but it echo only the block of the else statement. As I said, at least for me, the solution provided by @ishegg doesn't work. Any thoughts or ideas? – DaNoiseMan Aug 24 '17 at 15:58

0 Answers0