$tpltpl_handler =& xoops_gethandler('tplfile'); if (!isset($old_template[$upload_file])) { $tplfile =& $tpltpl_handler->find('default', null, null, $moddir, $upload_file); if (count($tplfile) > 0) { $tpl =& $tplfile[0]->xoopsClone(); $tpl->setVar('tpl_id', 0); $tpl->setVar('tpl_tplset', $tplset); } else { $msg[] = 'Template file <b>' . $upload_file . '</b> does not need to be installed (PHP files using this template file does not exist)'; continue; } } else { $tpl =& $tpltpl_handler->get($old_template[$upload_file]); } $tpl->setVar('tpl_lastmodified', time()); $fp = @fopen($uploader->getSavedDestination(), 'r'); $fsource = @fread($fp, filesize($uploader->getSavedDestination())); @fclose($fp); $tpl->setVar('tpl_source', $fsource, true); @unlink($uploader->getSavedDestination()); if (!$tpltpl_handler->insert($tpl)) { $msg[] = 'Failed inserting data for ' . $upload_file . ' to database'; } else { $msg[] = 'Template file <b>' . $upload_file . '</b> updated.'; if ($tplset == $xoopsConfig['template_set']) { include_once XOOPS_ROOT_PATH . '/class/template.php'; if (xoops_template_touch($tpl->getVar('tpl_id'), true)) { $msg[] = 'Template file <b>' . $upload_file . '</b> compiled.'; } } }
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $myxoopsConfigUser['avatar_maxsize'], $myxoopsConfigUser['avatar_width'], $myxoopsConfigUser['avatar_height']); $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); $xoops_upload_file = $formdata->getValueArray('post', 'xoops_upload_file', 's', true); if ($uploader->fetchMedia($xoops_upload_file[0])) { $uploader->setPrefix('cavt'); if ($uploader->upload()) { $avt_handler =& xoops_gethandler('avatar'); $avatar =& $avt_handler->create(); $avatar->setVar('avatar_file', $uploader->getSavedFileName()); $avatar->setVar('avatar_name', $u_obj->getVar('uname', 'n'), true); // not gpc $avatar->setVar('avatar_mimetype', $uploader->getMediaType()); $avatar->setVar('avatar_display', 1); $avatar->setVar('avatar_type', 'C'); if (!$avt_handler->insert($avatar)) { @unlink($uploader->getSavedDestination()); } else { $oldavatar = $u_obj->getVar('user_avatar', 's'); if (!empty($oldavatar) && $oldavatar != 'blank.gif' && !preg_match('/^savt/', strtolower($oldavatar))) { $avatars =& $avt_handler->getObjects(new Criteria('avatar_file', $oldavatar)); $avt_handler->delete($avatars[0]); $oldavatar_path = str_replace("\\", '/', realpath(XOOPS_UPLOAD_PATH . '/' . $oldavatar)); if (0 === strpos($oldavatar_path, XOOPS_UPLOAD_PATH) && is_file($oldavatar_path)) { unlink($oldavatar_path); } } $u_obj->setVar('user_avatar', $uploader->getSavedFileName(), true); // not gpc $u_handler->insert($u_obj); $avt_handler->addUser($avatar->getVar('avatar_id'), $uid); redirect_header('showusers.php', 0, _US_PROFUPDATED);
if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) { if (!$uploader->upload()) { $err[] = $uploader->getErrors(); } else { $image_handler =& xoops_gethandler('image'); $image =& $image_handler->create(); $image->setVar('image_name', $uploader->getSavedFileName()); $image->setVar('image_nicename', $image_nicename); $image->setVar('image_mimetype', $uploader->getMediaType()); $image->setVar('image_created', time()); $image_display = empty($image_display) ? 0 : 1; $image->setVar('image_display', $image_display); $image->setVar('image_weight', $image_weight); $image->setVar('imgcat_id', $imgcat_id); if ($imagecategory->getVar('imgcat_storetype') == 'db') { $fp = @fopen($uploader->getSavedDestination(), 'rb'); $fbinary = @fread($fp, filesize($uploader->getSavedDestination())); @fclose($fp); $image->setVar('image_body', $fbinary, true); @unlink($uploader->getSavedDestination()); } if (!$image_handler->insert($image)) { $err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename')); } } } else { $err[] = sprintf(_FAILFETCHIMG, $i); $err = array_merge($err, $uploader->getErrors(false)); } } if (count($err) > 0) {
if (Resourcesmkdirs(XOOPS_UPLOAD_PATH . '/' . $xoopsModule->dirname())) { $upload_path = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->dirname(); } // upload image if (!empty($_FILES['cat_image']['name'])) { include_once XOOPS_ROOT_PATH . '/class/uploader.php'; $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/x-png'); $maxfilesize = 500000; $maxfilewidth = 1200; $maxfileheight = 1200; $uploader = new XoopsMediaUploader($upload_path, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight); if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { $uploader->setPrefix('cat_'); if (!$uploader->upload()) { $error_upload = $uploader->getErrors(); } elseif (file_exists($uploader->getSavedDestination())) { if ($cat_obj->getVar("cat_image")) { @unlink($upload_path . '/' . $cat_obj->getVar("cat_image")); } $cat_obj->setVar('cat_image', $uploader->getSavedFileName()); } } } // delete iamge if (isset($_POST['delete_image']) && empty($_FILES['cat_image']['name'])) { @unlink($upload_path . '/' . $cat_obj->getVar("cat_image")); $cat_obj->setVar('cat_image', ''); } // insert object if ($cat_id = $category_handler->insert($cat_obj)) { redirect_header('admin.category.php', 3, '保存成功');
/** * Upload the file and Save into database * * @param text $title A litle description of the file * @param text $path_upload The path to where the file should be uploaded * @param text $author the author of the music or audio file * @return bool FALSE if upload fails or database fails */ function receiveAudio($title, $path_upload, $author, $maxfilebytes) { global $xoopsUser, $xoopsDB, $_POST, $_FILES; //busca id do user logado $uid = $xoopsUser->getVar('uid'); //create a hash so it does not erase another file //$hash1 = date(); //$hash = substr($hash1,0,4); // mimetypes and settings put this in admin part later $allowed_mimetypes = array("audio/mp3", "audio/x-mp3", "audio/mpeg"); $maxfilesize = $maxfilebytes; // create the object to upload $uploader = new XoopsMediaUploader($path_upload, $allowed_mimetypes, $maxfilesize); // fetch the media if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { //lets create a name for it $uploader->setPrefix('aud_' . $uid . '_'); //now let s upload the file if (!$uploader->upload()) { // if there are errors lets return them echo "<div style=\"color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center\"><p>" . $uploader->getErrors() . "</p></div>"; return false; } else { // now let s create a new object audio and set its variables //echo "passei aqui"; $audio = $this->create(); $url = $uploader->getSavedFileName(); $audio->setVar("url", $url); $audio->setVar("title", $title); $audio->setVar("author", $author); $uid = $xoopsUser->getVar('uid'); $audio->setVar("uid_owner", $uid); $this->insert($audio); $saved_destination = $uploader->getSavedDestination(); //print_r($_FILES); } } else { echo "<div style=\"color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center\"><p>" . $uploader->getErrors() . "</p></div>"; return false; } return true; }
function dispatch() { if($this->isGuest()){ redirect_header(XOOPS_URL, 2, _NOPERM); } require XSNS_FRAMEWORK_DIR.'/global.php'; require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; require_once XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/user.php'; if (!$this->validateToken('upload')) { redirect_header(XSNS_URL_MYPAGE_PROFILE, 3, _US_NOEDITRIGHT); } $config_handler =& xoops_gethandler('config'); if(defined('XOOPS_CUBE_LEGACY')){ $xoopsConfigUser =& $config_handler->getConfigsByDirname('user'); } else{ $xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER); } $xoops_upload_file = array(); $uid = 0; if (!empty($_POST['xoops_upload_file']) && is_array($_POST['xoops_upload_file'])){ $xoops_upload_file = $_POST['xoops_upload_file']; } if (!empty($_POST['uid'])) { $uid = intval($_POST['uid']); } if (empty($uid) || $xoopsUser->getVar('uid') != $uid ) { redirect_header(XSNS_URL_MYPAGE_PROFILE, 3, _US_NOEDITRIGHT); } if ($xoopsConfigUser['avatar_allow_upload'] == 1 && $xoopsUser->getVar('posts') >= $xoopsConfigUser['avatar_minposts']) { require_once XOOPS_ROOT_PATH.'/class/uploader.php'; $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $xoopsConfigUser['avatar_maxsize'], $xoopsConfigUser['avatar_width'], $xoopsConfigUser['avatar_height']); $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { $uploader->setPrefix('cavt'); if ($uploader->upload()) { $avt_handler =& xoops_gethandler('avatar'); $avatar =& $avt_handler->create(); $avatar->setVar('avatar_file', $uploader->getSavedFileName()); $avatar->setVar('avatar_name', $xoopsUser->getVar('uname')); $avatar->setVar('avatar_mimetype', $uploader->getMediaType()); $avatar->setVar('avatar_display', 1); $avatar->setVar('avatar_type', 'C'); if (!$avt_handler->insert($avatar)) { @unlink($uploader->getSavedDestination()); } else { $oldavatar = $xoopsUser->getVar('user_avatar'); if (!empty($oldavatar) && $oldavatar != 'blank.gif' && !preg_match("/^savt/", strtolower($oldavatar))) { $avatars =& $avt_handler->getObjects(new Criteria('avatar_file', $oldavatar)); $avt_handler->delete($avatars[0]); $oldavatar_path = str_replace("\\", "/", realpath(XOOPS_UPLOAD_PATH.'/'.$oldavatar)); if (0 === strpos($oldavatar_path, XOOPS_UPLOAD_PATH) && is_file($oldavatar_path)) { unlink($oldavatar_path); } } $sql = sprintf("UPDATE %s SET user_avatar = %s WHERE uid = %u", $this->db->prefix('users'), $this->db->quoteString($uploader->getSavedFileName()), $xoopsUser->getVar('uid')); $this->db->query($sql); $avt_handler->addUser($avatar->getVar('avatar_id'), $xoopsUser->getVar('uid')); redirect_header(XSNS_URL_MYPAGE_PROFILE, 2, _US_PROFUPDATED); } } } redirect_header(XSNS_URL_MYPAGE_PROFILE, 2, _MD_XSNS_PROFILE_AVATAR_UPLOAD_NG); } redirect_header(XSNS_URL_MYPAGE_PROFILE, 2, _MD_XSNS_PROFILE_AVATAR_UPLOAD_NG); }
function receiveTribe($tribe_title, $tribe_desc, $tribe_img, $path_upload, $maxfilebytes, $maxfilewidth, $maxfileheight, $change_img = 1, $tribe = "") { global $xoopsUser, $xoopsDB, $_POST, $_FILES; //busca id do user logado $uid = $xoopsUser->getVar('uid'); if (!is_a($tribe, "yogurt_tribes")) { $tribe = $this->create(); } else { $tribe->unsetNew(); } if ($change_img == 1) { // mimetypes and settings put this in admin part later $allowed_mimetypes = array('image/jpeg', 'image/pjpeg'); $maxfilesize = $maxfilebytes; // create the object to upload $uploader = new XoopsMediaUploader($path_upload, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight); // fetch the media if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { //lets create a name for it $uploader->setPrefix('tribe_' . $uid . '_'); //now let s upload the file if (!$uploader->upload()) { // if there are errors lets return them echo "<div style=\"color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center\"><p>" . $uploader->getErrors() . "</p></div>"; return false; } else { // now let s create a new object picture and set its variables $url = $uploader->getSavedFileName(); $saved_destination = $uploader->getSavedDestination(); $image_name = $this->resizeImage2($saved_destination, 125, 80, $path_upload); $tribe->setVar("tribe_img", $image_name); } } else { echo "<div style=\"color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center\"><p>" . $uploader->getErrors() . "</p></div>"; return false; } } $tribe->setVar("tribe_title", $tribe_title); $tribe->setVar("tribe_desc", $tribe_desc); $tribe->setVar("owner_uid", $uid); $this->insert($tribe); return true; }
/** * Upload the file and Save into database * * @param text $title A litle description of the file * @param text $path_upload The path to where the file should be uploaded * @param int $thumbwidth the width in pixels that the thumbnail will have * @param int $thumbheight the height in pixels that the thumbnail will have * @param int $pictwidth the width in pixels that the pic will have * @param int $pictheight the height in pixels that the pic will have * @param int $maxfilebytes the maximum size a file can have to be uploaded in bytes * @param int $maxfilewidth the maximum width in pixels that a pic can have * @param int $maxfileheight the maximum height in pixels that a pic can have * @return bool FALSE if upload fails or database fails */ function receivePicture($title, $path_upload, $thumbwidth, $thumbheight, $pictwidth, $pictheight, $maxfilebytes, $maxfilewidth, $maxfileheight) { global $xoopsUser, $xoopsDB, $_POST, $_FILES; //busca id do user logado $uid = $xoopsUser->getVar('uid'); //create a hash so it does not erase another file //$hash1 = date(); //$hash = substr($hash1,0,4); // mimetypes and settings put this in admin part later $allowed_mimetypes = array('image/jpeg', 'image/pjpeg'); $maxfilesize = $maxfilebytes; // create the object to upload $uploader = new XoopsMediaUploader($path_upload, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight); // fetch the media if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { //lets create a name for it $uploader->setPrefix('pic_' . $uid . '_'); //now let s upload the file if (!$uploader->upload()) { // if there are errors lets return them echo "<div style=\"color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center\"><p>" . $uploader->getErrors() . "</p></div>"; return false; } else { // now let s create a new object picture and set its variables $picture = $this->create(); $url = $uploader->getSavedFileName(); $picture->setVar("url", $url); $picture->setVar("title", $title); $picture->setVar("private", 0); $uid = $xoopsUser->getVar('uid'); $picture->setVar("uid_owner", $uid); $this->insert($picture); $saved_destination = $uploader->getSavedDestination(); //print_r($_FILES); //$this->resizeImage($saved_destination,false, $thumbwidth, $thumbheight, $pictwidth, $pictheight,$path_upload); //$this->resizeImage($saved_destination,true, $thumbwidth, $thumbheight, $pictwidth, $pictheight,$path_upload); $this->resizeImage($saved_destination, $thumbwidth, $thumbheight, $pictwidth, $pictheight, $path_upload); } } else { echo "<div style=\"color:#FF0000; background-color:#FFEAF4; border-color:#FF0000; border-width:thick; border-style:solid; text-align:center\"><p>" . $uploader->getErrors() . "</p></div>"; return false; } return true; }