Index: file/file.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/file/file.module,v
retrieving revision 1.48
diff -u -p -r1.48 file.module
--- file/file.module	19 Dec 2006 03:52:57 -0000	1.48
+++ file/file.module	20 Dec 2006 21:59:25 -0000
@@ -527,27 +527,58 @@ function ec_file_build_download($file) {
   }
 }
 
+
+/**
+ * Log and display a file error.
+ *
+ * @param $mssg
+ *   The error message to display.
+ * @param $add_system_error
+ *   Set TRUE to append any available system error info.
+ */
+function ec_file_error($mssg, $add_system_error = true) {
+  // $php_errormsg set only if "track_errors" config setting is on.
+  if ($add_system_error && ! empty($php_errormsg)) {
+     $mssg .= t(" [%errormsg]", array("%errormsg" => $php_errormsg));
+  }
+  watchdog("ecommerce/file", $mssg, WATCHDOG_ERROR);
+  die($mssg);
+}
+
+
 /**
- * Transfer file using http to client. Pipes a file through Drupal to the
- * client.
+ * Transfer file using http to client.
+ *
+ * Pipes a file through Drupal to the client.
  *
- * @param $source File to transfer.
- * @param $headers An array of http headers to send along with file.
+ * @param $source
+ *   File to transfer.
+ * @param $headers
+ *   An array of http headers to send along with file.
  */
 function ec_file_transfer($source, $headers) {
   ob_end_clean();
 
+  $source_path = ec_file_create_path($source);
+  $fd = fopen($source_path, 'rb');
+  if (! $fd) {
+    ec_file_error(t("Error opening %file", array("%file" => $source_path)));
+  }
+
   foreach ($headers as $header) {
     header($header);
   }
 
-  $source = ec_file_create_path($source);
-
   // Transfer file in 1024 byte chunks to save memory usage.
-  $fd = fopen($source, 'rb');
   while (!feof($fd)) {
-    print fread($fd, 1024);
+    $buf = fread($fd, 1024);
+    if ($buf === FALSE) {
+      // Unfortunately, because this is a download, user may not see the error.
+      ec_file_error(t("Error sending %file", array("%file" => $source_path)));
+    }
+    print $buf;
   }
+
   fclose($fd);
   exit();
 }
