Reply to Re: Splitting uploads up/ concatenating them back together

Your name:

Reply:


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)

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация