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);
?>
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
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 ?
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.
I have a big kml file I would just like to get certain parts of it.
<td>MUNICITY PSGC</td>
<td>153606000</td>
</tr>
<tr bgcolor="#D4E4F3">
<td>MUNICITY NAME</td>
<td>BUBONG</td>
<coordinates> 121.9116664538692,6.448888587819113,0 121.9119650206403,6.449515350125353,0 121.9119422292838,6.449720472334889,0 121.9122248421055,6.45000080602091,0 121.9122248421055,6.450554635986066,0 121.912635086524,6.450967159540255,0 121.9127809512066,6.451110745086737,0 121.9127809512066,6.4513887996373,0 121.9124983383845,6.451666854187351,0 121.9124983383845,6.451944908737914,0 121.9122248421055,6.452222963288534,0 121.9122248421055,6.45305484780431,0 121.9116664538692,6.453610956904925,0 121.9116664538692,6.454440562285072,0 121.9108345693535,6.455277005071878,0 121.9108345693535,6.455555059622498,0 121.9105519565314,6.455833114172549,0 121.9105519565314,6.456111168723112,0 121.9102784602525,6.45639150240919,0 121.9091571255082,6.45639150240919,0 121.9077759692987,6.455001229657285,0 121.9077759692987,6.454720895971263,0 121.9075001938841,6.454445120556159,0 121.9075001938841,6.453610956904925,0 121.9076301046167,6.452879354358174,0 121.9078283894188,6.452177380575449,0 121.9080266742212,6.451500477284355,0 121.9082249590239,6.450880552385172,0 121.9083320783998,6.450292535384961,0 121.9083639862988,6.449711355791806,0 121.9084323603685,6.44918715459022,0 121.9088904666361,6.448610533268493,0 121.909163962915,6.44833247871793,0 121.9097223511518,6.44833247871793,0 121.9099730560743,6.448090890338392,0 121.9116664538692,6.448888587819113,0</coordinates>
The end file should be (in an excel or csv file
Municity PSGC Municity Name Coordinates
153606000 BUBONG 121.9116664538692,6.448888587819113,0 121.9119650206403,6.449515350125353,0 121.9119422292838,6.449720472334889,0 121.9122248421055,6.45000080602091,0 121.9122248421055,6.450554635986066,0 121.912635086524,6.450967159540255,0 121.9127809512066,6.451110745086737,0 121.9127809512066,6.4513887996373,0 121.9124983383845,6.451666854187351,0 121.9124983383845,6.451944908737914,0 121.9122248421055,6.452222963288534,0 121.9122248421055,6.45305484780431,0 121.9116664538692,6.453610956904925,0 121.9116664538692,6.454440562285072,0 121.9108345693535,6.455277005071878,0 121.9108345693535,6.455555059622498,0 121.9105519565314,6.455833114172549,0 121.9105519565314,6.456111168723112,0 121.9102784602525,6.45639150240919,0 121.9091571255082,6.45639150240919,0 121.9077759692987,6.455001229657285,0 121.9077759692987,6.454720895971263,0 121.9075001938841,6.454445120556159,0 121.9075001938841,6.453610956904925,0 121.9076301046167,6.452879354358174,0 121.9078283894188,6.452177380575449,0 121.9080266742212,6.451500477284355,0 121.9082249590239,6.450880552385172,0 121.9083320783998,6.450292535384961,0 121.9083639862988,6.449711355791806,0 121.9084323603685,6.44918715459022,0 121.9088904666361,6.448610533268493,0 121.909163962915,6.44833247871793,0 121.9097223511518,6.44833247871793,0 121.9099730560743,6.448090890338392,0 121.9116664538692,6.448888587819113,0
Does anyone know of a PHP or Python Script to get this.
Thanks again guys.
I think you want to export to excel without HTML tags and show the result this way , so try this one :
<?php
header( "Content-type: application/vnd.ms-excel; charset=UTF-16LE" );
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename='".date("Y-m-d")."'.xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
?>
<table><tr><td>MUNICITY PSGC</td><td>MUNICITY NAME</td><td>coordinates</td></tr>
<tr align=center><td valign=top>153606000</td><td valign=top>BUBONG </td><td valign=top>121.9116664538692,6.448888587819113,0 121.9119650206403,6.449515350125353,0 121.9119422292838,6.449720472334889,0 121.9122248421055,6.45000080602091,0 121.9122248421055,6.450554635986066,0 121.912635086524,6.450967159540255,0 121.9127809512066,6.451110745086737,0 121.9127809512066,6.4513887996373,0 121.9124983383845,6.451666854187351,0 121.9124983383845,6.451944908737914,0 121.9122248421055,6.452222963288534,0 121.9122248421055,6.45305484780431,0 121.9116664538692,6.453610956904925,0 121.9116664538692,6.454440562285072,0 121.9108345693535,6.455277005071878,0 121.9108345693535,6.455555059622498,0 121.9105519565314,6.455833114172549,0 121.9105519565314,6.456111168723112,0 121.9102784602525,6.45639150240919,0 121.9091571255082,6.45639150240919,0 121.9077759692987,6.455001229657285,0 121.9077759692987,6.454720895971263,0 121.9075001938841,6.454445120556159,0 121.9075001938841,6.453610956904925,0 121.9076301046167,6.452879354358174,0 121.9078283894188,6.452177380575449,0 121.9080266742212,6.451500477284355,0 121.9082249590239,6.450880552385172,0 121.9083320783998,6.450292535384961,0 121.9083639862988,6.449711355791806,0 121.9084323603685,6.44918715459022,0 121.9088904666361,6.448610533268493,0 121.909163962915,6.44833247871793,0 121.9097223511518,6.44833247871793,0 121.9099730560743,6.448090890338392,0 121.9116664538692,6.448888587819113,0</td></tr><table>