You are here: Re: HELP! Trying to add Email Notification to Download File Code « PHP Programming Language « IT news, forums, messages
Re: HELP! Trying to add Email Notification to Download File Code

Posted by matt on 11/16/06 03:11

Pedro Graca wrote:
> matt wrote:
>
>>Warning: Invalid argument supplied for foreach() in
>>/public_html/file_download.php on line 27
>
>
> When the
>
> $_SESSION['files'] = file_list(DOWNLOAD_DIRECTORY, FILE_VALIDITY_RX);
>
> fails, for whatever reason, $_SESSION['files'] would be false.
> When $_SESSION['files'] is false, the foreach() produces that warning.
>
> In the new 'controlling' script I added a check for $_SESSION['files']
> and introduced the regular expression to check validity of files as
> another define'd constant.
>
> Hope it works now.
>
>
>
>
>
>
>
> <?php
> require 'file_download.inc.php';
>
> ### some constants
> define('DOWNLOAD_DIRECTORY', '.');
> define('EMAIL_ADMIN', 'admin@example.com');
> ### The regular expression will match all files with png, gif, jpg or
> ### bmp extension, in a case insensitive manner
> define('FILE_VALIDITY_RX', '/\.(?:png|gif|jpg|bmp)$/i');
>
> # if the directory contents change between requests
> # the file sent to the client and the file requested may
> # be different. To avoid that, the file list is saved
> # in a session variable.
> session_start();
> if (!isset($_SESSION['files'])) {
> $_SESSION['files'] = file_list(DOWNLOAD_DIRECTORY, FILE_VALIDITY_RX);
> }
>
> # If the request is for a valid file, send the
> # file (and mail the admin) and exit.
> if (isset($_GET['id']) && download_id_is_valid($_GET['id'], $_SESSION['files'])) {
> if (send_file_by_id($_GET['id'], $_SESSION['files'], DOWNLOAD_DIRECTORY)) {
> mail(EMAIL_ADMIN, 'downloads', 'file sent');
> exit();
> }
> }
>
> # display file list links
> if ($_SESSION['files']) {
> foreach ($_SESSION['files'] as $k=>$f) {
> echo '<a href="' . $_SERVER['PHP_SELF'] . '?id=', $k, '">', $f, "</a><br>\n";
> }
> } else {
> echo "No files available to download.<br>\n";
> }
> ?>
>
Thanks again, I really appreciate the work you put in, it's going now,
working perfectly!

 

Navigation:

[Reply to this 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация