cc-3936: Refactored php code to upload files
This commit is contained in:
parent
6a16cf0084
commit
d1e7341046
|
@ -853,58 +853,55 @@ class Application_Model_StoredFile
|
||||||
{
|
{
|
||||||
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
|
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
|
||||||
Logging::info('copyFileToStor: moving file '.$audio_file);
|
Logging::info('copyFileToStor: moving file '.$audio_file);
|
||||||
$md5 = md5_file($audio_file);
|
|
||||||
$duplicate = Application_Model_StoredFile::RecallByMd5($md5, true);
|
|
||||||
|
|
||||||
$result = null;
|
$storDir = Application_Model_MusicDir::getStorDir();
|
||||||
if ($duplicate) {
|
$stor = $storDir->getDirectory();
|
||||||
if (file_exists($duplicate->getFilePath())) {
|
// check if "organize" dir exists and if not create one
|
||||||
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
|
if (!file_exists($stor."/organize")) {
|
||||||
$result = array( "code" => 106, "message" => "An identical audioclip named '$duplicateName' already exists on the server.");
|
if (!mkdir($stor."/organize", 0777)) {
|
||||||
|
return array(
|
||||||
|
"code" => 109,
|
||||||
|
"message" => "Failed to create 'organize' directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($result)) {//The file has no duplicate, so proceed to copy.
|
if (chmod($audio_file, 0644) === false) {
|
||||||
$storDir = Application_Model_MusicDir::getStorDir();
|
Logging::info("Warning: couldn't change permissions of $audio_file to 0644");
|
||||||
$stor = $storDir->getDirectory();
|
|
||||||
// check if "organize" dir exists and if not create one
|
|
||||||
if (!file_exists($stor."/organize")) {
|
|
||||||
if (!mkdir($stor."/organize", 0777)) {
|
|
||||||
$result = array("code" => 109, "message" => "Failed to create 'organize' directory.");
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chmod($audio_file, 0644) === false) {
|
|
||||||
Logging::info("Warning: couldn't change permissions of $audio_file to 0644");
|
|
||||||
}
|
|
||||||
|
|
||||||
//check to see if there is enough space in $stor to continue.
|
|
||||||
if (self::isEnoughDiskSpaceToCopy($stor, $audio_file)) {
|
|
||||||
$audio_stor = Application_Common_OsPath::join($stor, "organize", $fileName);
|
|
||||||
|
|
||||||
if (self::liquidsoapFilePlayabilityTest($audio_file)) {
|
|
||||||
|
|
||||||
Logging::info("copyFileToStor: moving file $audio_file to $audio_stor");
|
|
||||||
|
|
||||||
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
|
|
||||||
if (@rename($audio_file, $audio_stor) === false) {
|
|
||||||
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
|
|
||||||
#warn the user that the file wasn't uploaded and they should check if there is enough disk space.
|
|
||||||
unlink($audio_file);//remove the file after failed rename
|
|
||||||
$result = array("code" => 108, "message" => "The file was not uploaded, this error can occur if the computer hard drive does not have enough disk space or the stor directory does not have correct write permissions.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result = array("code" => 110, "message" => "This file appears to be corrupted and will not be added to media library.");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$result = array("code" => 107, "message" => "The file was not uploaded, there is ".$freeSpace."MB of disk space left and the file you are uploading has a size of ".$fileSize."MB.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
// Check if we have enough space before copying
|
||||||
|
if(!self::isEnoughDiskSpaceToCopy($stor, $audio_file)) {
|
||||||
|
$freeSpace = disk_free_space($stor);
|
||||||
|
return array("code" => 107,
|
||||||
|
"message" => "The file was not uploaded, there is
|
||||||
|
".$freeSpace."MB of disk space left and the file you are
|
||||||
|
uploading has a size of ".$fileSize."MB.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if liquidsoap can play this file
|
||||||
|
if(!self::liquidsoapFilePlayabilityTest($audio_file)) {
|
||||||
|
return array(
|
||||||
|
"code" => 110,
|
||||||
|
"message" => "This file appears to be corrupted and will not
|
||||||
|
be added to media library.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Did all the checks for realz, now trying to copy
|
||||||
|
$audio_stor = Application_Common_OsPath::join($stor, "organize", $fileName);
|
||||||
|
Logging::info("copyFileToStor: moving file $audio_file to $audio_stor");
|
||||||
|
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
|
||||||
|
if (@rename($audio_file, $audio_stor) === false) {
|
||||||
|
#something went wrong likely there wasn't enough space in the audio_stor to move the file too.
|
||||||
|
#warn the user that the file wasn't uploaded and they should check if there is enough disk space.
|
||||||
|
unlink($audio_file);//remove the file after failed rename
|
||||||
|
return array(
|
||||||
|
"code" => 108,
|
||||||
|
"message" => "
|
||||||
|
The file was not uploaded, this error can occur if the computer
|
||||||
|
hard drive does not have enough disk space or the stor
|
||||||
|
directory does not have correct write permissions. ");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue