2

I have problem. I created a web page with upload files, I have database (MySQL) with correctly URL to file (file path) (in database is only url to the file, file is in folder on the server). And now I trying write/search php script to download this file what was uploaded. All at web works well, but this download scripts don't work. I read and I think best way for me will be download with 'header', but I was trying and nothing. File is download to our disk, name is correctly, file extension ok, file is open in correct program, but if file have in name chars (';',':' etc.) file is download without these chars and is incorrectly (lack of extension, bad name). And second problem: all downloaded files are empty (0 b size), all is ok but they are empty, some tips ? Thanks in advance for help

My bad download codes:

<?php
    $data=date('Y-m-d_H:i:s');
    $nazwa=$_POST['downtitle'];
    $urlek=$_POST['downurl'];
    $extrozsz=$_POST['downext'];
    $filePath = $urlek;
    $fileName = $nazwa.$data.".".$extrozsz;

    //------------------------------------------------------------------------

//  $fd = fopen($filePath,"r");
//  $size = filesize($filePath);
//  $contents = fread($fd, filesize($filePath));

//  fclose($fd);

//  header("Content-Type: application/octet-stream");
//  header("Content-Length: $size;");
//  header("Content-Disposition: attachment; filename=$fileName");

//  echo $contents;

    //----------------------------------------------------------------------


//      set_time_limit(0);    
//      while( $urlek = $response->fetch() )
//      {
//      $my_pliki = file_get_contents("$urlek");
//      $my_file = fopen("$urlek","w+");
//      fwrite($my_file,$my_pliki);
//      fclose($my_file);
//      }

//----------------------------------------------------------------------------

$quoted = $filePath;
$size   = filesize($file);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);

?>

didi
  • 21
  • 3

3 Answers3

0

The filename parameter has some limits which are well described in RFC6266

So when you want use characters that are not present in the ISO-8859-1 character set then you need to use either filename* header or you need to strip/replace these characters from the filename. Nice solution to do so can be found here

Community
  • 1
  • 1
Robert
  • 19,800
  • 5
  • 55
  • 85
0

Thanks, I edit my php at this:

<?php
    $data=date('Y-m-d_H:i:s');
    $nazwa=$_POST['downtitle'];
    $urlek=$_POST['downurl'];
    $extrozsz=$_POST['downext'];
    $filePath = $urlek;
    $fileName = $nazwa.$data.".".$extrozsz;

        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Disposition: attachment; filename=\"" . $fileName."\"");
        header("Content-Description: File Transfer");
        readfile($filePath);

?>

And all is now ok, but I have one question now: In MySQL database I have title, description, added date, premiere date and I wish to have search field. I done it in input type="search", but what script now use for searching in this specified tables in database, firstly open database this I know, but what later what command is for search in database ? I know about 'like' but some better? And after all return correct result and show all from database where this search word is ok Some tips? Sorry for weak english and thanks.

Martin
  • 22,212
  • 11
  • 70
  • 132
didi
  • 21
  • 3
  • Is this an answer to your own question or an edit to the original question? You seem to be answering your question with another question. Bad practise. It is best if you ask a new question re: `I have one question...` – Martin Aug 12 '16 at 15:04
  • Agree. You now have 3 question under one heading, so somebody able and willing will never see the last questions. Also, you might get suggested answers while you pose your question – Leif Neland Aug 14 '16 at 09:34
0

Ok all is now ok, but another problem. I have code for showing news at website. All news are showing at same time (too long site). I wish to have at bottom of website numbers (at all websites under are this for forwarding on second subpage with older news). But how do it? Sup or sub is for small word, numbers etc, but all is retrieved form database:

$zapytanie='SELECT * FROM filetable WHERE Section="Other" ORDER BY ID DESC LIMIT 10';

This is in my php code query for showing latest 10 news, but if I add normally small numbers at bottom how construct code for showing next 10 news (no at where id="10-11" because if I will be have 1 thousand news or more it is too primitive) I must have automated code for showing pages with nextly 10 or 20 news how ?

didi
  • 21
  • 3
  • `LIMIT` can take two arguments, the **offset** and the **return count**, so you can do `LIMIT , ` so `LIMIT 20,10` will return 10 records starting from the 21st record (21->30) . [MySQL Manual](https://dev.mysql.com/doc/refman/5.5/en/select.html) – Martin Aug 12 '16 at 15:08