Проблема такая что не отображаеться правильная ссылка на файл для скачки.Сделал чтобы отображалась, но получается что скачивать приходиться текстовый файл.
PHP код:
<?php include 'config.php';
function check_result($code) {
global $prices, $ntp_user_id;
foreach($prices as $i => $key){
$answer = file_get_contents("http://sms.techpoint.lv/confirm.php?code=$code&id=$ntp_user_id&price=$key", FALSE, NULL, 0, 140);
if ($answer == 'key_ok') {
return $key;
}
}
}
if(isset($_GET['id']) && is_numeric($_GET['id'])){
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM shop_items WHERE id = '$id' LIMIT 1") or die(mysql_error());
$file = mysql_fetch_assoc($query);
echo '<h1>'.$file['name'].'</h1>';
echo '<p>'.$file['description'].'</p>';
echo '<p>Size: '.$file['filesize'].' bytes</p>';
echo '<p>Sūti tekstu '.$keyword_name.$file['price'].' uz numuru 157 LMT/Tele2/Bite (SMS cena '.$price_values[$file['price']].')';
?>
<form id="smsform" name="smsform" method="post">
<label for="code">Saņemtais SMS kods:</label>
<input type="text" name="code" id="code" /> <br />
<input type="submit" name="Submit" value="Submit" class="submit"/>
</form>
<?php
if(isset($_POST['Submit'])){
$key = check_result($_POST['code']);
if(!isset($key)) {
$errors[] = 'Ievadītais kods ir nepareizs, izlietots vai ar iztecējušu derīguma termiņu!';
while (list($key,$value) = each($errors))
{
echo '<div class="msgError">'.$value.'</div><font style="font-size: 3px;"><br /></font>';
}
}
if($key == $file['price']){
$id = md5(date('r', time()));
$filename = $file['filename'];
$fileid = $file['id'];
$added = time();
$insert = mysql_query("INSERT INTO shop_links (id, filename, fileid, added) VALUES ('$id', '$filename', '$fileid', '$added')") or die(mysql_error());
echo 'Šī ir tava lejupielādes saite :<a href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?gief='.$id.'>http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?gief='.$id.'</a> Tā būs pieejama '.$shop_link_expair_time.' minūtes.';
}else{
echo 'Šim kodam ir nepareiza vērtība.';
}
}
}elseif(isset($_GET['gief'])){
$id = $_GET['gief'];
$query = mysql_query("SELECT * FROM shop_links WHERE id = '$id'") or die (mysql_error());
$row = mysql_fetch_assoc($query);
if(empty($row)){
echo 'Šāda saite neeksistē.';
}else{
if($row['added'] + $shop_link_expair_time * 60 > time()){
$path = $shop_filedir.$row['filename']; // the file made available for download via this PHP file
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path); // outputs the content of the file
exit();
}else{
echo 'Šīs saites laiks ir beidzies';
}
}
}else{
echo '<h1>Faili veikalā</h1>';
echo '<table border="1">';
echo '<tr>
<th>Id:</th>
<th>Name:</th>
<th>Description:</th>
<th>Size:</th>
<th>Price:</th>
<th>Buy</th>
</tr>';
$query = mysql_query("SELECT * FROM shop_items") or die(mysql_error());
while($row = mysql_fetch_assoc($query)){
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['name'].'</td>
<td>'.$row['description'].'</td>
<td>'.$row['filesize'].'</td>
<td>'.$row['price'].'</td>
<td><a href="?id='.$row['id'].'">Buy</a></td>
</tr>';
}
echo '</table>';
}
?>