2016-12-13 3 views
-2
<?php 
    $counter = 'www.mywebsite.com/counter/counter.txt'; 
    $download = 'www.mywebsite.com/file/1.pdf'; 

    $number = file_get_contents($counter); // read count file 
    $number++; // increment count by 1 
    $fh = fopen($counter, 'w'); // open count file for writing 
    fwrite($fh, $number); // write new count to count file 
    fclose($fh); // close count file 
    header("Location: $download"); // get download 

?> 

Почему счетчик чисел после ex: 5,999 перезапуск на 5000 ??? а не до 6 000?Счетчик приращений ++ неправильный номер

+0

Мы не знаем, что в этих файлах, как мы можем вам помочь? –

ответ

0
<?php 
    $counter = 'www.mywebsite.com/counter/counter.txt'; 
    $download = 'www.mywebsite.com/file/1.pdf'; 

    $number = intval(file_get_contents($counter)); // read count file 
    $number++; // increment count by 1 
    $fh = fopen($counter, 'w'); // open count file for writing 
    fwrite($fh, $number); // write new count to count file 
    fclose($fh); // close count file 
    header("Location: $download"); // get download 

?>

!!! intval() ... Исправлено.

Смежные вопросы