summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjartan Mannes <kjartan@2.no-reply.drupal.org>2004-02-27 11:25:13 +0000
committerKjartan Mannes <kjartan@2.no-reply.drupal.org>2004-02-27 11:25:13 +0000
commit16c1bcada10b739a74d3374bc62bcf1883b7c640 (patch)
treea133df54d4b4e824a76a0a5ffd6981d80e604d03
parentdf2c03372906df166daccbbeb4cfd4540d798160 (diff)
downloadbrdo-16c1bcada10b739a74d3374bc62bcf1883b7c640.tar.gz
brdo-16c1bcada10b739a74d3374bc62bcf1883b7c640.tar.bz2
- Fixed constants problem.
- Made filename modification more logical when there was no extension.
-rw-r--r--includes/file.inc32
1 files changed, 18 insertions, 14 deletions
diff --git a/includes/file.inc b/includes/file.inc
index 11893402b..27fcd181c 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -11,13 +11,6 @@ define('FILE_DOWNLOADS_PUBLIC', 1);
define('FILE_DOWNLOADS_PRIVATE', 2);
define('FILE_SEPARATOR', PHP_OS == 'WINNT' ? '\\' : '/');
-// Required for file uploads to work with PHP 4.2
-define('UPLOAD_ERR_OK', 0);
-define('UPLOAD_ERR_INI_SIZE', 1);
-define('UPLOAD_ERR_FORM_SIZE', 2);
-define('UPLOAD_ERR_PARTIAL', 3);
-define('UPLOAD_ERR_NO_FILE', 4);
-
/**
* Create the download path to a file.
*/
@@ -182,11 +175,17 @@ function file_copy(&$source, $dest = 0, $replace = 0) {
// and find a new filename.
$pos = strrpos($basename, '.');
$name = substr($basename, 0, $pos);
- $ext = substr($basename, $pos);
+ if ($pos = strrpos($basename, '.')) {
+ $name = substr($basename, 0, $pos);
+ $ext = substr($basename, $pos);
+ }
+ else {
+ $name = $basename;
+ }
+
$counter = 0;
do {
$dest = $directory . FILE_SEPARATOR . $name .'_'. $counter++ . $ext;
- $counter++;
} while (file_exists($dest));
}
@@ -256,13 +255,18 @@ function file_save_upload($source, $dest = 0, $replace = 0) {
// Check for file upload errors.
switch ($file->error) {
- case UPLOAD_ERR_PARTIAL:
- case UPLOAD_ERR_NO_FILE:
+ case 0: // UPLOAD_ERR_OK
+ break;
+ case 1: // UPLOAD_ERR_INI_SIZE
+ case 2: // UPLOAD_ERR_FORM_SIZE
+ drupal_set_message(t("file upload failed: file size too big."), 'error');
+ return 0;
+ case 3: // UPLOAD_ERR_PARTIAL
+ case 4: // UPLOAD_ERR_NO_FILE
drupal_set_message(t("file upload failed: incomplete upload."), 'error');
return 0;
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- drupal_set_message(t("file upload failed: file size too big."), 'error');
+ default: // Unknown error
+ drupal_set_message(t("file upload failed: unkown error."), 'error');
return 0;
}