Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Jak stworzyć link do pliku.
Forum PHP.pl > Forum > Przedszkole
renovatio
Witam!
Mam taki skrypt do konwersji avi na flv
Problem polega na tym że mam linijkę kodu:

  1. echo'<html><p><a href="'.$new_flv.'">KLIKNIJ TUTAJ ABY POBRAĆ SWÓJ FILMIK</a></p></html>';


jest to link do przerobionego już pliku w formacie flv.
Chodzi o to że jak odpalam to na windows to klikając w ten link plik jest pobierany na dysk.
Jeżeli odpalam na debianie to przeglądarka otwiera plik zamiast go pobrać.
JAK PRZEROBIĆ ŻEBY TA LINIJKA BYŁA UNIWERSALNA I KAŻDY KTO KLIKNIE W LINK POBIERZE PLIK.

PODAJE CAŁY KOD:
  1. <?php
  2.  
  3. function sizeinput($input, $len)
  4. {
  5. (int)$len;
  6. (string)$input;
  7. $n = substr($input, 0,$len);
  8. $ret = trim($n);
  9. $out = htmlentities($ret, ENT_QUOTES);
  10. return $out;
  11. }
  12.  
  13. function checkfile($input)
  14. {
  15. $ext = array('avi');
  16. $extfile = substr($input['name'],-4);
  17. $extfile = explode('.',$extfile);
  18. $good = array();
  19. $extfile = $extfile[1];
  20.  
  21. if(in_array($extfile, $ext))
  22. {
  23. $good['safe'] = true;
  24. $good['ext'] = $extfile;
  25. }
  26. else
  27. {
  28. $good['safe'] = false;
  29. }
  30.  
  31. return $good;
  32. }
  33.  
  34. if($_POST && array_key_exists("vid_file", $_FILES))
  35. {
  36. //$uploaddir is for videos before conversion
  37. $uploaddir = 'uploads/videos/';
  38. //$live_dir is for videos after converted to flv
  39. $live_dir = 'uploads/live/';
  40. $seed = rand(1,2009) * rand(1,10);
  41. $upload = $seed. basename($_FILES['vid_file']['name']);
  42. $uploadfile = $uploaddir .$upload;
  43. $vid_cat = (int)$_POST['vid_cat'];
  44. $safe_file = checkfile($_FILES['vid_file']);
  45. if($safe_file['safe'] == 1)
  46. {
  47. if (move_uploaded_file($_FILES['vid_file']['tmp_name'], $uploadfile))
  48. {
  49. chmod($uploadfile,0777);
  50. $base = basename($uploadfile, $safe_file['ext']);
  51. $new_file = $base.'flv';
  52. $new_flv = $live_dir.$new_file;
  53. //ececute ffmpeg generate flv
  54. shell_exec('ffmpeg -i '.$uploadfile.' -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv '.$new_flv.'');
  55. chmod($new_flv,0777);
  56. echo'<html><p><a href="'.$new_flv.'">KLIKNIJ TUTAJ ABY POBRAĆ SWÓJ FILMIK</a></p></html>';
  57. echo'<html align="center"><p><a href="index.php">POWRÓT DO STRONY GŁÓWNEJ</a></p><html>';
  58. }
  59. else
  60. {
  61. echo "Possible file upload attack!\n";
  62. print_r($_FILES);
  63. }
  64.  
  65. }
  66. else
  67. {
  68. echo 'Niewłaściwy format pliku. Spróbuj jeszcze raz. Twój plik musi być typu .avi';
  69. }
  70. }
  71. ?>
  72. <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  73. <table width="600" border="0" align="center" cellpadding="2" cellspacing="2">
  74. <tr>
  75. <td width="260" align="left" colspan="3"><div align="center">
  76. <h3>ZAŁADUJ VIDEO </h3>
  77. <h3>Zaczekaj aż plik zostanie wysłany na serwer i przekonwertowany.</h3>
  78. </div>
  79. </td>
  80. </tr>
  81. <tr>
  82. <td width="260" align="center"></td>
  83. <td width="326" align="center"></td>
  84. </tr>
  85. <tr>
  86. </tr>
  87. <tr>
  88. <td align="left"><input name="vid_file" type="file" id="vid_file" /></td>
  89. </tr>
  90. <tr>
  91. </tr>
  92. <tr>
  93. </tr>
  94. <tr>
  95. <td>
  96. </td>
  97. <td><input type="submit" name="Submit" value="Konwertuj" /></td>
  98. </tr>
  99. </table>
  100. </form>
  101.  


DZIĘKUJĘ
camikazee
Powinno wystarczyć readfile
maniana
Najprostszym sposobem:
Cytat
echo'<html><p><a href="download.php?file='.$new_flv.'">KLIKNIJ TUTAJ ABY POBRAĆ SWÓJ FILMIK</a></p></html>';

przekierowanie linku do pliku download.php
Cytat
<?php
$file = basename($_GET['file']);
$storage_path = 'storage/';
header('Content-type: video/x-flv');
header('Content-Disposition: attachment; filename="'.$file.'"');
header("Content-Length: ".filesize( $storage_path.$file ));
readfile( $storage_path.$file );
exit;
?>
renovatio
Kod działa ,ale pobierany plik ma 0 albo 1KB zależnie od systemu(debian,windows).
Dla pewności sprawdziłem czy plik w folderze z którego jest pobierany jest dobry i z nim jest wszystko ok.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.