本文整理汇总了PHP中UploadFile::setDir方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadFile::setDir方法的具体用法?PHP UploadFile::setDir怎么用?PHP UploadFile::setDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadFile
的用法示例。
在下文中一共展示了UploadFile::setDir方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
function save()
{
$jshopConfig = JSFactory::getConfig();
require_once $jshopConfig->path . 'lib/uploadfile.class.php';
$dispatcher = JDispatcher::getInstance();
$db = JFactory::getDBO();
$value_id = JRequest::getInt("value_id");
$attr_id = JRequest::getInt("attr_id");
$post = JRequest::get("post");
$attributValue = JSFactory::getTable('attributValue', 'jshop');
$dispatcher->trigger('onBeforeSaveAttributValue', array(&$post));
$upload = new UploadFile($_FILES['image']);
$upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
$upload->setDir($jshopConfig->image_attributes_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
if ($post['old_image']) {
@unlink($jshopConfig->image_attributes_path . "/" . $post['old_image']);
}
$post['image'] = $upload->getName();
@chmod($jshopConfig->image_attributes_path . "/" . $post['image'], 0777);
} else {
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
saveToLog("error.log", "SaveAttributeValue - Error upload image. code: " . $upload->getError());
}
}
if (!$value_id) {
$query = "SELECT MAX(value_ordering) AS value_ordering FROM `#__jshopping_attr_values` where attr_id='" . $db->escape($attr_id) . "'";
$db->setQuery($query);
$row = $db->loadObject();
$post['value_ordering'] = $row->value_ordering + 1;
}
if (!$attributValue->bind($post)) {
JError::raiseWarning("", _JSHOP_ERROR_BIND);
$this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&attr_id=" . $attr_id);
return 0;
}
if (!$attributValue->store()) {
JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
$this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&attr_id=" . $attr_id);
return 0;
}
$dispatcher->trigger('onAfterSaveAttributValue', array(&$attributValue));
if ($this->getTask() == 'apply') {
$this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&task=edit&attr_id=" . $attr_id . "&value_id=" . $attributValue->value_id);
} else {
$this->setRedirect("index.php?option=com_jshopping&controller=attributesvalues&attr_id=" . $attr_id);
}
}
示例2: save
function save()
{
$mainframe = JFactory::getApplication();
$jshopConfig = JSFactory::getConfig();
require_once $jshopConfig->path . 'lib/uploadfile.class.php';
$id = JRequest::getInt("id");
$productLabel = JTable::getInstance('productLabel', 'jshop');
$post = JRequest::get("post");
$lang = JSFactory::getLang();
$post['name'] = $post[$lang->get("name")];
JPluginHelper::importPlugin('jshoppingadmin');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onBeforeSaveProductLabel', array(&$post));
$upload = new UploadFile($_FILES['image']);
$upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
$upload->setDir($jshopConfig->image_labels_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
if ($post['old_image']) {
@unlink($jshopConfig->image_labels_path . "/" . $post['old_image']);
}
$post['image'] = $upload->getName();
@chmod($jshopConfig->image_labels_path . "/" . $post['image'], 0777);
} else {
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
saveToLog("error.log", "Label - Error upload image. code: " . $upload->getError());
}
}
if (!$productLabel->bind($post)) {
JError::raiseWarning("", _JSHOP_ERROR_BIND);
$this->setRedirect("index.php?option=com_jshopping&controller=productlabels");
return 0;
}
if (!$productLabel->store()) {
JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
$this->setRedirect("index.php?option=com_jshopping&controller=productlabels");
return 0;
}
$dispatcher->trigger('onAfterSaveProductLabel', array(&$productLabel));
if ($this->getTask() == 'apply') {
$this->setRedirect("index.php?option=com_jshopping&controller=productlabels&task=edit&id=" . $productLabel->id);
} else {
$this->setRedirect("index.php?option=com_jshopping&controller=productlabels");
}
}
示例3: uploadImage
function uploadImage($post)
{
$jshopConfig = JSFactory::getConfig();
$dispatcher = JDispatcher::getInstance();
$upload = new UploadFile($_FILES['category_image']);
$upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
$upload->setDir($jshopConfig->image_category_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
$name = $upload->getName();
if ($post['old_image'] && $name != $post['old_image']) {
@unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
}
@chmod($jshopConfig->image_category_path . "/" . $name, 0777);
if ($post['size_im_category'] < 3) {
if ($post['size_im_category'] == 1) {
$category_width_image = $jshopConfig->image_category_width;
$category_height_image = $jshopConfig->image_category_height;
} else {
$category_width_image = JRequest::getInt('category_width_image');
$category_height_image = JRequest::getInt('category_height_image');
}
$path_full = $jshopConfig->image_category_path . "/" . $name;
$path_thumb = $jshopConfig->image_category_path . "/" . $name;
if ($category_width_image || $category_height_image) {
if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
saveToLog("error.log", "SaveCategory - Error create thumbail");
}
}
@chmod($jshopConfig->image_category_path . "/" . $name, 0777);
}
$category_image = $name;
$dispatcher->trigger('onAfterSaveCategoryImage', array(&$post, &$category_image, &$path_full, &$path_thumb));
} else {
$category_image = '';
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
}
}
return $category_image;
}
示例4: uploadFiles
function uploadFiles($product, $product_id, $post)
{
$jshopConfig = JSFactory::getConfig();
$dispatcher = JDispatcher::getInstance();
if (!isset($post['product_demo_descr'])) {
$post['product_demo_descr'] = '';
}
if (!isset($post['product_file_descr'])) {
$post['product_file_descr'] = '';
}
if (!isset($post['product_file_sort'])) {
$post['product_file_sort'] = '';
}
for ($i = 0; $i < $jshopConfig->product_file_upload_count; $i++) {
$file_demo = "";
$file_sale = "";
if ($jshopConfig->product_file_upload_via_ftp != 1) {
$upload = new UploadFile($_FILES['product_demo_file_' . $i]);
$upload->setDir($jshopConfig->demo_product_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
$file_demo = $upload->getName();
@chmod($jshopConfig->demo_product_path . "/" . $file_demo, 0777);
} else {
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_FILE_DEMO);
saveToLog("error.log", "SaveProduct - Error upload demo. code: " . $upload->getError());
}
}
unset($upload);
$upload = new UploadFile($_FILES['product_file_' . $i]);
$upload->setDir($jshopConfig->files_product_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
$file_sale = $upload->getName();
@chmod($jshopConfig->files_product_path . "/" . $file_sale, 0777);
} else {
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_FILE_SALE);
saveToLog("error.log", "SaveProduct - Error upload file sale. code: " . $upload->getError());
}
}
unset($upload);
}
if (!$file_demo && isset($post['product_demo_file_name_' . $i]) && $post['product_demo_file_name_' . $i]) {
$file_demo = $post['product_demo_file_name_' . $i];
}
if (!$file_sale && isset($post['product_file_name_' . $i]) && $post['product_file_name_' . $i]) {
$file_sale = $post['product_file_name_' . $i];
}
if ($file_demo != "" || $file_sale != "") {
$this->addToProductFiles($product_id, $file_demo, $post['product_demo_descr_' . $i], $file_sale, $post['product_file_descr_' . $i], $post['product_file_sort_' . $i]);
}
}
//Update description files
$this->productUpdateDescriptionFiles($post['product_demo_descr'], $post['product_file_descr'], $post['product_file_sort']);
}
示例5: save
function save()
{
$jshopConfig = JSFactory::getConfig();
require_once $jshopConfig->path . 'lib/image.lib.php';
require_once $jshopConfig->path . 'lib/uploadfile.class.php';
$dispatcher = JDispatcher::getInstance();
$apply = JRequest::getVar("apply");
$_alias = JSFactory::getModel("alias");
$db = JFactory::getDBO();
$man = JSFactory::getTable('manufacturer', 'jshop');
$man_id = JRequest::getInt("manufacturer_id");
$post = JRequest::get("post");
$_lang = JSFactory::getModel("languages");
$languages = $_lang->getAllLanguages(1);
foreach ($languages as $lang) {
$post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
$post['alias_' . $lang->language] = $post['name_' . $lang->language];
}
$post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, 0, $man_id)) {
$post['alias_' . $lang->language] = "";
JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
}
$post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
$post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
}
if (!$post['manufacturer_publish']) {
$post['manufacturer_publish'] = 0;
}
$dispatcher->trigger('onBeforeSaveManufacturer', array(&$post));
if (!$man->bind($post)) {
JError::raiseWarning("", _JSHOP_ERROR_BIND);
$this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
return 0;
}
if (!$man_id) {
$man->ordering = null;
$man->ordering = $man->getNextOrder();
}
$upload = new UploadFile($_FILES['manufacturer_logo']);
$upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
$upload->setDir($jshopConfig->image_manufs_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
if ($post['old_image']) {
@unlink($jshopConfig->image_manufs_path . "/" . $post['old_image']);
}
$name = $upload->getName();
@chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
if ($post['size_im_category'] < 3) {
if ($post['size_im_category'] == 1) {
$category_width_image = $jshopConfig->image_category_width;
$category_height_image = $jshopConfig->image_category_height;
} else {
$category_width_image = JRequest::getInt('category_width_image');
$category_height_image = JRequest::getInt('category_height_image');
}
$path_full = $jshopConfig->image_manufs_path . "/" . $name;
$path_thumb = $jshopConfig->image_manufs_path . "/" . $name;
if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color, $jshopConfig->image_interlace)) {
JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
saveToLog("error.log", "SaveManufacturer - Error create thumbail");
}
@chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
unset($img);
}
$man->manufacturer_logo = $name;
} else {
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
saveToLog("error.log", "SaveManufacturer - Error upload image. code: " . $upload->getError());
}
}
if (!$man->store()) {
JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
$this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
return 0;
}
$dispatcher->trigger('onAfterSaveManufacturer', array(&$man));
if ($this->getTask() == 'apply') {
$this->setRedirect("index.php?option=com_jshopping&controller=manufacturers&task=edit&man_id=" . $man->manufacturer_id);
} else {
$this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
}
}
示例6: save
function save()
{
$mainframe = JFactory::getApplication();
$jshopConfig = JSFactory::getConfig();
require_once JPATH_COMPONENT_SITE . '/lib/uploadfile.class.php';
require_once JPATH_COMPONENT_SITE . "/lib/csv.io.class.php";
$ie_id = JRequest::getInt("ie_id");
if (!$ie_id) {
$ie_id = $this->get('ie_id');
}
$lang = JSFactory::getLang();
$db = JFactory::getDBO();
$_importexport = JSFactory::getTable('ImportExport', 'jshop');
$_importexport->load($ie_id);
$alias = $_importexport->get('alias');
$_importexport->set('endstart', time());
$_importexport->store();
//get list tax
$query = "SELECT tax_id, tax_value FROM `#__jshopping_taxes`";
$db->setQuery($query);
$rows = $db->loadObjectList();
$listTax = array();
foreach ($rows as $row) {
$listTax[intval($row->tax_value)] = $row->tax_id;
}
//get list category
$query = "SELECT category_id as id, `" . $lang->get("name") . "` as name FROM `#__jshopping_categories`";
$db->setQuery($query);
$rows = $db->loadObjectList();
$listCat = array();
foreach ($rows as $row) {
$listCat[$row->name] = $row->id;
}
$_products = JSFactory::getModel('products', 'JshoppingModel');
$dir = $jshopConfig->importexport_path . $alias . "/";
$upload = new UploadFile($_FILES['file']);
$upload->setAllowFile(array('csv'));
$upload->setDir($dir);
if ($upload->upload()) {
$filename = $dir . "/" . $upload->getName();
@chmod($filename, 0777);
$csv = new csv();
$data = $csv->read($filename);
if (is_array($data)) {
foreach ($data as $k => $row) {
if (count($row) < 2 || $k == 0) {
continue;
}
$tax_value = intval($row[5]);
if (!isset($listTax[$tax_value])) {
$tax = JSFactory::getTable('tax', 'jshop');
$tax->set('tax_name', $tax_value);
$tax->set('tax_value', $tax_value);
$tax->store();
$listTax[$tax_value] = $tax->get("tax_id");
}
$category_name = $row['6'];
if (!isset($listCat[$category_name]) && $category_name != "") {
$cat = JSFactory::getTable("category", "jshop");
$query = "SELECT max(ordering) FROM `#__jshopping_categories`";
$db->setQuery($query);
$ordering = $db->loadResult() + 1;
$cat->set($lang->get("name"), $category_name);
$cat->set("category_ordertype", 1);
$cat->set("products_page", $jshopConfig->count_products_to_page);
$cat->set("products_row", $jshopConfig->count_products_to_row);
$cat->set("category_publish", 0);
$cat->set("ordering", $ordering);
$cat->store();
$listCat[$category_name] = $cat->get("category_id");
}
$product = JSFactory::getTable('product', 'jshop');
$product->set("product_ean", $row[1]);
$product->set("product_quantity", $row[2]);
$product->set("product_date_added", $row[3]);
$product->set("product_price", $row[4]);
$product->set("min_price", $row[4]);
$product->set("product_tax_id", $listTax[$tax_value]);
$product->set("currency_id", $jshopConfig->mainCurrency);
$product->set($lang->get("name"), utf8_encode($row[7]));
$product->set($lang->get("short_description"), utf8_encode($row[8]));
$product->set($lang->get("description"), utf8_encode($row[9]));
$product->store();
$product_id = $product->get("product_id");
$category_id = $listCat[$category_name];
if ($category_name != "" && $category_id) {
$_products->setCategoryToProduct($product_id, array($category_id));
}
unset($product);
}
}
@unlink($filename);
} else {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING);
}
if (!JRequest::getInt("noredirect")) {
$mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=" . $ie_id, _JSHOP_COMPLETED);
}
}
示例7: save
function save()
{
$mainframe = JFactory::getApplication();
$jshopConfig = JSFactory::getConfig();
require_once $jshopConfig->path . 'lib/image.lib.php';
require_once $jshopConfig->path . 'lib/uploadfile.class.php';
JPluginHelper::importPlugin('jshoppingadmin');
$dispatcher = JDispatcher::getInstance();
$_alias = $this->getModel("alias");
$db = JFactory::getDBO();
$category = JTable::getInstance("category", "jshop");
if (!$_POST["category_id"]) {
$_POST['category_add_date'] = getJsDate();
}
if (!isset($_POST['category_publish'])) {
$_POST['category_publish'] = 0;
}
$post = JRequest::get('post');
$_lang = $this->getModel("languages");
$languages = $_lang->getAllLanguages(1);
if ($post['category_parent_id'] == $post['category_id']) {
$post['category_parent_id'] = 0;
}
$dispatcher->trigger('onBeforeSaveCategory', array(&$post));
foreach ($languages as $lang) {
$post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
$post['alias_' . $lang->language] = $post['name_' . $lang->language];
}
$post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, $post['category_id'], 0)) {
$post['alias_' . $lang->language] = "";
JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
}
$post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
$post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
}
if (!$category->bind($post)) {
JError::raiseWarning("", _JSHOP_ERROR_BIND);
$this->setRedirect("index.php?option=com_jshopping&controller=categories");
return 0;
}
$edit = $category->category_id;
$upload = new UploadFile($_FILES['category_image']);
$upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
$upload->setDir($jshopConfig->image_category_path);
$upload->setFileNameMd5(0);
$upload->setFilterName(1);
if ($upload->upload()) {
$name = $upload->getName();
if ($post['old_image'] && $name != $post['old_image']) {
@unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
}
@chmod($jshopConfig->image_category_path . "/" . $name, 0777);
if ($post['size_im_category'] < 3) {
if ($post['size_im_category'] == 1) {
$category_width_image = $jshopConfig->image_category_width;
$category_height_image = $jshopConfig->image_category_height;
} else {
$category_width_image = JRequest::getInt('category_width_image');
$category_height_image = JRequest::getInt('category_height_image');
}
$path_full = $jshopConfig->image_category_path . "/" . $name;
$path_thumb = $jshopConfig->image_category_path . "/" . $name;
if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
saveToLog("error.log", "SaveCategory - Error create thumbail");
}
@chmod($jshopConfig->image_category_path . "/" . $name, 0777);
unset($img);
}
$category->category_image = $name;
} else {
if ($upload->getError() != 4) {
JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
}
}
$this->_reorderCategory($category);
if (!$category->store()) {
JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
$this->setRedirect("index.php?option=com_jshopping&controller=categories");
return 0;
}
$dispatcher->trigger('onAfterSaveCategory', array(&$category));
$success = $edit ? _JSHOP_CATEGORY_SUCC_UPDATE : _JSHOP_CATEGORY_SUCC_ADDED;
if ($this->getTask() == 'apply') {
$this->setRedirect('index.php?option=com_jshopping&controller=categories&task=edit&category_id=' . $category->category_id, $success);
} else {
$this->setRedirect('index.php?option=com_jshopping&controller=categories', $success);
}
}