/** * Save file */ function dt_save_file($edit) { global $item, $file, $tpl, $xoopsTpl, $mc, $dtfunc; foreach ($_POST as $k => $v) { ${$k} = $v; } $db = XoopsDatabaseFactory::getDatabaseConnection(); if ($edit) { //Verificamos que la característica exista $fl = new DTFile($file); if ($fl->isNew()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('Specified file does not exists!', 'dtransport')); } } else { $fl = new DTFile(); } $tc = TextCleaner::getInstance(); //Comprueba que el título de la característica no exista $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_files') . " WHERE title='{$title}' AND id_file!=" . $fl->id() . " AND id_soft=" . $item->id(); list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('Another log with same title already exists!', 'dtransport')); } // Check if a file has been provided if ($_FILES['thefile']['name'] == '') { // Comprobamos si se ha proporcionado un archivo if (!$edit && !$remote) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('You must provide a file to upload!', 'dtransport')); } elseif ($remote && $url == '') { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('You must provide a file URL when remote type is activated!', 'dtransport')); } } else { if ($edit && !$fl->remote()) { $path = $item->getVar('secure') ? rtrim($mc['directory_secure'], '/') . '/' . $fl->file() : rtrim($mc['directory_insecure']) . '/' . $fl->file(); unlink($path); } if ($item->getVar('secure')) { $dir = $mc['directory_secure']; } else { $dir = $mc['directory_insecure']; } include RMCPATH . '/class/uploader.php'; $uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']); if (!$uploader->fetchMedia('thefile')) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors()); } if (!$uploader->upload()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors()); } } $fl->setSoftware($item->id()); $fl->setTitle($title); $fname = !$uploader && $edit ? $remote ? $url : $fl->file() : $uploader->getSavedFileName(); $fl->setFile($fname); $fl->setRemote($remote); $fl->setGroup($group); $fl->setDefault($default); $fl->setDate(time()); $fl->setSize($remote ? '' : (isset($uploader) ? $uploader->getMediaSize() : $fl->size())); $fl->setMime($remote ? '' : (isset($uploader) ? $uploader->getMediaType() : $fl->mime())); if (!$fl->save()) { redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' . ($edit ? 'edit/' . $fl->id() : '') : '/?p=cpanel&action=files&id=' . $item->id() . ($edit ? '&op=edit&file=' . $fl->id() : '')), 1, __('File could not be saved! Please try again.', 'dtransport')); } if ($fl->isDefault()) { $db->queryF("UPDATE " . $db->prefix("dtrans_files") . " SET `default`=0 WHERE id_soft=" . $item->id() . " AND id_file !=" . $fl->id()); } redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('File saved successfully!', 'dtransport')); }
$sw = new DTSoftware($item); if ($sw->isNew()) { error(__('Specified download item does not exists!', 'dtransport')); } if ($sw->getVar('secure')) { $dir = $mc['directory_secure']; if (!is_dir($dir)) { if (!mkdir($dir, 511)) { error(__('Directory for protected downloads does not exists!', 'dtransport')); } } } else { $dir = $mc['directory_insecure']; if (!is_dir($dir)) { if (!mkdir($dir, 511)) { error(__('Directory for downloads does not exists!', 'dtransport')); } } } include RMCPATH . '/class/uploader.php'; $uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']); $err = array(); if (!$uploader->fetchMedia('Filedata')) { error($uploader->getErrors()); } if (!$uploader->upload()) { error($uploader->getErrors()); } $ret = array('file' => $uploader->getSavedFileName(), 'dir' => $uploader->getSavedDestination(), 'token' => $data[4], 'size' => $rmu->formatBytesSize($uploader->getMediaSize()), 'fullsize' => $uploader->getMediaSize(), 'type' => $uploader->getMediaType(), 'secure' => $sw->getVar('secure') ? __('Protected Download', 'dtransport') : __('Normal Download', 'dtransport'), 'error' => 0); echo json_encode($ret); die;