- Fixed constants problem.
- Made filename modification more logical when there was no extension.4.4.x
parent
df2c033729
commit
16c1bcada1
|
@ -11,13 +11,6 @@ define('FILE_DOWNLOADS_PUBLIC', 1);
|
||||||
define('FILE_DOWNLOADS_PRIVATE', 2);
|
define('FILE_DOWNLOADS_PRIVATE', 2);
|
||||||
define('FILE_SEPARATOR', PHP_OS == 'WINNT' ? '\\' : '/');
|
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.
|
* Create the download path to a file.
|
||||||
*/
|
*/
|
||||||
|
@ -181,12 +174,18 @@ function file_copy(&$source, $dest = 0, $replace = 0) {
|
||||||
// Destination file already exists and we can't replace is so we try and
|
// Destination file already exists and we can't replace is so we try and
|
||||||
// and find a new filename.
|
// and find a new filename.
|
||||||
$pos = strrpos($basename, '.');
|
$pos = strrpos($basename, '.');
|
||||||
|
$name = substr($basename, 0, $pos);
|
||||||
|
if ($pos = strrpos($basename, '.')) {
|
||||||
$name = substr($basename, 0, $pos);
|
$name = substr($basename, 0, $pos);
|
||||||
$ext = substr($basename, $pos);
|
$ext = substr($basename, $pos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$name = $basename;
|
||||||
|
}
|
||||||
|
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
do {
|
do {
|
||||||
$dest = $directory . FILE_SEPARATOR . $name .'_'. $counter++ . $ext;
|
$dest = $directory . FILE_SEPARATOR . $name .'_'. $counter++ . $ext;
|
||||||
$counter++;
|
|
||||||
} while (file_exists($dest));
|
} while (file_exists($dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,13 +255,18 @@ function file_save_upload($source, $dest = 0, $replace = 0) {
|
||||||
|
|
||||||
// Check for file upload errors.
|
// Check for file upload errors.
|
||||||
switch ($file->error) {
|
switch ($file->error) {
|
||||||
case UPLOAD_ERR_PARTIAL:
|
case 0: // UPLOAD_ERR_OK
|
||||||
case UPLOAD_ERR_NO_FILE:
|
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');
|
drupal_set_message(t("file upload failed: incomplete upload."), 'error');
|
||||||
return 0;
|
return 0;
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
default: // Unknown error
|
||||||
case UPLOAD_ERR_FORM_SIZE:
|
drupal_set_message(t("file upload failed: unkown error."), 'error');
|
||||||
drupal_set_message(t("file upload failed: file size too big."), 'error');
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue