Skip to content

Instantly share code, notes, and snippets.

@skrosoft
Last active August 28, 2015 19:43
Show Gist options
  • Save skrosoft/06bd711cb3a9e14e83cd to your computer and use it in GitHub Desktop.
Save skrosoft/06bd711cb3a9e14e83cd to your computer and use it in GitHub Desktop.
fix ezmultiupload giving the file extension name to uploaded file. This fix a webdav listing folder problem !
<?php
$items = eZPersistentObject::fetchObjectList( eZBinaryFile::definition(), null, array( ), null, null, true );
foreach ($items as $item){
$original = $item->attribute('original_filename');
$filename = $item->attribute('filename');
$original_has_extension = !(strpos($original, '.') === false);
$has_extension = !(strpos($filename, '.') === false);
if (!$original_has_extension) continue;
$extension = pathinfo($original, PATHINFO_EXTENSION);
if ($has_extension){
$filename_extension = pathinfo($filename, PATHINFO_EXTENSION);
if ($filename_extension == $extension){
continue;
}
}
$new_filename = $filename . '.' . $extension;
//echo $filename . ' -> ' . $new_filename .' (' . $original . ')<br>';
$mimeType = $item->attribute( 'mime_type' );
$storageDir = eZSys::storageDirectory();
list( $group, $type ) = explode( '/', $mimeType );
$filePath = eZSys::siteDir() . $storageDir . '/original/' . $group . '/' . $filename;
$newFilePath = eZSys::siteDir() . $storageDir . '/original/' . $group . '/' . $new_filename;
if (!file_exists($filePath)){
if (file_exists($newFilePath)){
$item->setAttribute('filename', $new_filename);
$item->store();
}
continue;
}
//echo '====> ' . $filePath . ' => ' . $newFilePath . '<br>';
rename($filePath, $newFilePath);
$item->setAttribute('filename', $new_filename);
$item->store();
}
eZExecution::cleanExit();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment