Révision 59ae487e
Ajouté par Assos Assos il y a presque 7 ans
drupal7/sites/all/modules/file_entity/file_entity.pages.inc | ||
---|---|---|
35 | 35 |
if (!is_file($file->uri)) { |
36 | 36 |
return MENU_NOT_FOUND; |
37 | 37 |
} |
38 |
|
|
38 |
// @todo Remove this once drupal_basename is fixed for PHP versions greater |
|
39 |
// than '5.3.29'. |
|
40 |
$basename_function = version_compare(PHP_VERSION,'5.3.29','>') ? 'basename' : 'drupal_basename'; |
|
39 | 41 |
$headers = array( |
40 | 42 |
'Content-Type' => mime_header_encode($file->filemime), |
41 |
'Content-Disposition' => 'attachment; filename="' . mime_header_encode(drupal_basename($file->uri)) . '"',
|
|
43 |
'Content-Disposition' => 'attachment; filename="' . mime_header_encode($basename_function($file->uri)) . '"',
|
|
42 | 44 |
'Content-Length' => $file->filesize, |
43 | 45 |
'Content-Transfer-Encoding' => 'binary', |
44 | 46 |
'Pragma' => 'no-cache', |
... | ... | |
77 | 79 |
* - Edit fields |
78 | 80 |
* Skip this step if there are no fields on this entity type. |
79 | 81 |
*/ |
80 |
function file_entity_add_upload($form, &$form_state, array $options = array()) { |
|
82 |
function file_entity_add_upload($form, &$form_state, $options = array()) { |
|
83 |
if (!is_array($options)) { |
|
84 |
$options = array($options); |
|
85 |
} |
|
81 | 86 |
$step = (isset($form_state['step']) && in_array($form_state['step'], array(1, 2, 3, 4))) ? $form_state['step'] : 1; |
82 | 87 |
$form['#step'] = $step; |
83 | 88 |
$form['#options'] = $options; |
... | ... | |
398 | 403 |
// We have the filetype, check if we can skip step 4. |
399 | 404 |
if (($form['#step'] == 3 && $trigger == 'edit-next')) { |
400 | 405 |
$file = file_load($form_state['storage']['upload']); |
406 |
$form_state['file'] = $file; |
|
401 | 407 |
if (!field_info_instances('file', $form_state['storage']['type'])) { |
402 | 408 |
// This filetype doesn't have fields, save the file. |
403 | 409 |
$save = TRUE; |
... | ... | |
800 | 806 |
if (!empty($form_state['values']['replace_upload'])) { |
801 | 807 |
$replacement = $form_state['values']['replace_upload']; |
802 | 808 |
// Move file from temp to permanent home. |
803 |
$destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($replacement->uri); |
|
804 |
$replace_mode = $destination_uri == $file->uri ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME; |
|
805 |
if ($new_file_uri = file_unmanaged_copy($replacement->uri, $destination_uri, $replace_mode)) { |
|
806 |
// @todo Add watchdog() about replaced file here? |
|
807 |
|
|
808 |
// Remove temporary file. |
|
809 |
file_delete($replacement); |
|
810 |
|
|
811 |
// Update if the uri target has changed. |
|
812 |
if ($new_file_uri != $file->uri) { |
|
813 |
// Store the original file uri to delete if save is successful. |
|
814 |
$orphaned_uri = $file->uri; |
|
815 |
|
|
816 |
// Update file entity uri. |
|
817 |
$file->uri = $new_file_uri; |
|
809 |
if (pathinfo($replacement->uri, PATHINFO_EXTENSION) == pathinfo($file->uri, PATHINFO_EXTENSION)) { |
|
810 |
file_unmanaged_copy($replacement->uri, $file->uri, FILE_EXISTS_REPLACE); |
|
811 |
} else { |
|
812 |
$destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($replacement->uri); |
|
813 |
$replace_mode = $destination_uri == $file->uri ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME; |
|
814 |
if ($new_file_uri = file_unmanaged_copy($replacement->uri, $destination_uri, $replace_mode)) { |
|
815 |
// @todo Add watchdog() about replaced file here? |
|
816 |
|
|
817 |
// Remove temporary file. |
|
818 |
file_delete($replacement); |
|
819 |
|
|
820 |
// Update if the uri target has changed. |
|
821 |
if ($new_file_uri != $file->uri) { |
|
822 |
// Store the original file uri to delete if save is successful. |
|
823 |
$orphaned_uri = $file->uri; |
|
824 |
|
|
825 |
// Update file entity uri. |
|
826 |
$file->uri = $new_file_uri; |
|
827 |
} |
|
818 | 828 |
} |
819 | 829 |
} |
820 | 830 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules