|
Posted by Kim Andrι Akerψ on 09/25/05 04:05
nwheavyw8@gmail.com wrote:
> okay, my downloader script looks like this:
>
> <?php
>
> // Set some values
>
> $file = &$_GET['file'];
> $nomore = 0;
> $count = 1;
> $size = 0;
>
> // Get MIME type
>
> $handle = fopen($file.'/fmime', "r");
> $mime = file_get_contents($handle);
> fclose(handle);
>
> // Get file name
>
> $handle = fopen($file.'/fname', "r");
> $name = file_get_contents($handle);
> fclose(handle);
>
> // Get size of file
>
> while ($nomore = 0):
> if (file_exists($file.'/'.$count)):
> $size .= $size + filesize($file.'/'.$count);
> else:
> $nomore = 1;
> endif;
> endwhile;
>
>
> // Reset values
>
> $nomore = 0;
> $count = 1;
>
> // Concatenate file
>
> header("Content-length: $size"); //$size is the size of $content in
> bytes
> header("Content-type: $mime");
> header("Content-Disposition: attachment; filename=$name"); //whatever
> name you want to give the file
> while ($nomore = 0):
> if (file_exists($file.'/'.$count)):
> $handle = fopen($file.'/'.$count, "rb");
> $content = file_get_contents($handle);
> echo $content;
> fclose($handle);
> else:
> $nomore = 1;
> endif;
> endwhile;
>
> and I uploaded a little test file (already splitted and stuff), but
> when I try to download it, i get these errors:
>
>
> Warning: file_get_contents() expects parameter 1 to be string,
> resource given in /home/freehost/t35.com/l/i/lildude/downloader.php
> on line 13
>
> Warning: fclose(): supplied argument is not a valid stream resource in
> /home/freehost/t35.com/l/i/lildude/downloader.php on line 14
>
> Warning: file_get_contents() expects parameter 1 to be string,
> resource given in /home/freehost/t35.com/l/i/lildude/downloader.php
> on line 19
>
> Warning: fclose(): supplied argument is not a valid stream resource in
> /home/freehost/t35.com/l/i/lildude/downloader.php on line 20
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /home/freehost/t35.com/l/i/lildude/downloader.php:13) in
> /home/freehost/t35.com/l/i/lildude/downloader.php on line 40
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /home/freehost/t35.com/l/i/lildude/downloader.php:13) in
> /home/freehost/t35.com/l/i/lildude/downloader.php on line 41
>
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /home/freehost/t35.com/l/i/lildude/downloader.php:13) in
> /home/freehost/t35.com/l/i/lildude/downloader.php on line 42
>
> what am I doing wrong?
You're using the file_get_contents function incorrectly.
The following line:
$contents = file_get_contents($filename);
Is equivalent to the following lines:
$handle = fopen($filename,"r");
$contents = fread($handle,filesize($filename));
fclose($handle);
The "Cannot modify header information" errors are just errors that
follow due to the fact that the first error already has sent headers
back to the client in order to be displayed.
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Navigation:
[Reply to this message]
|