public static function uploadFile($file_data, $id, $filename, $hash, $extra_id = null)
 {
     $realHash = myContentStorage::getTempUploadHash($filename, $id);
     // TODO - what if there is  an error while uploading ?
     // filename is OK?
     if ($realHash == $hash && $hash != "") {
         //create the directory if doesn't exists (should have write permissons)
         // if(!is_dir("./files")) mkdir("./files", 0755);
         //move the uploaded file
         $origFilename = $file_data['name'];
         $parts = pathinfo($origFilename);
         $extension = strtolower($parts['extension']);
         $filename = $id . '_' . $filename;
         // add the file extension after the "." character
         $fullPath = myContentStorage::getFSUploadsPath() . $filename . ($extra_id ? "_" . $extra_id : "") . "." . $extension;
         myContentStorage::fullMkdir($fullPath);
         if (!move_uploaded_file($file_data['tmp_name'], $fullPath)) {
             KalturaLog::log("Error while uploading [{$id}] [{$filename}] [{$hash}] [{$extra_id}] " . print_r($file_data, true) . "\n->[{$fullPath}]");
             return false;
         }
         @chmod($fullPath, 0777);
         return true;
     }
     return false;
 }
 /**
  * This function returns the upload url paramters needed to securely upload a file.
  * The resulting parameters are filename and hash.
  * The filename is the given entity name (thumbnail, audio, etc...)
  * The hash is generated using the myContentStorage::getTempUploadHash function.
  * @param string $entityName = the entity object name
  * @param int $kuser_id = the uploading kuser id
  * @return string the url parameters string
  */
 public static function getTempUploadUrlParams($entityName, $kuser_id, $user = NULL)
 {
     // TODO - i added  this becuase it took me 3 hours to find this bug.
     // it's clear that the module from which this is called should enforce logging in, but i added this extra defence - Eran ??
     if ($kuser_id == NULL || strlen($kuser_id) == 0) {
         throw new Exception("Should not be called when user is not logged in !");
     }
     $hash = myContentStorage::getTempUploadHash($entityName, $kuser_id, $user);
     if ($hash != "") {
         return "?id={$kuser_id}&filename={$entityName}&hash={$hash}";
     }
     return "";
 }