当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductDownload::store方法代码示例

本文整理汇总了PHP中ProductDownload::store方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductDownload::store方法的具体用法?PHP ProductDownload::store怎么用?PHP ProductDownload::store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProductDownload的用法示例。


在下文中一共展示了ProductDownload::store方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: downloads

 /**
  * AJAX behavior to process uploaded files intended as digital downloads
  *
  * Handles processing a file upload from a temporary file to a
  * the correct storage container (DB, file system, etc)
  *
  * @author Jonathan Davis
  * @return string JSON encoded result with DB id, filename, type & size
  **/
 public static function downloads()
 {
     $error = false;
     if (isset($_FILES['Filedata']['error'])) {
         $error = $_FILES['Filedata']['error'];
     }
     if ($error) {
         die(json_encode(array('error' => Lookup::errors('uploads', $error))));
     }
     if (!@is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
         die(json_encode(array('error' => Shopp::__('The file could not be saved because the upload was not found on the server.'))));
     }
     if (0 == $_FILES['Filedata']['size']) {
         die(json_encode(array('error' => Shopp::__('The file could not be saved because the uploaded file is empty.'))));
     }
     FileAsset::mimetypes();
     // Save the uploaded file
     $File = new ProductDownload();
     $File->parent = 0;
     $File->context = "price";
     $File->type = "download";
     $File->name = $_FILES['Filedata']['name'];
     $File->filename = $File->name;
     list($extension, $mimetype, $properfile) = wp_check_filetype_and_ext($_FILES['Filedata']['tmp_name'], $File->name);
     if (empty($mimetype)) {
         $mimetype = 'application/octet-stream';
     }
     $File->mime = $mimetype;
     if (!empty($properfile)) {
         $File->name = $File->filename = $properfile;
     }
     $File->size = filesize($_FILES['Filedata']['tmp_name']);
     $File->store($_FILES['Filedata']['tmp_name'], 'upload');
     $Error = ShoppErrors()->code('storage_engine_save');
     if (!empty($Error)) {
         die(json_encode(array('error' => $Error->message(true))));
     }
     $File->save();
     do_action('add_product_download', $File, $_FILES['Filedata']);
     echo json_encode(array('id' => $File->id, 'name' => stripslashes($File->name), 'type' => $File->mime, 'size' => $File->size));
 }
开发者ID:forthrobot,项目名称:inuvik,代码行数:50,代码来源:Warehouse.php

示例2: shopp_add_product_download

/**
 * shopp_add_product_download
 *
 * Add product download file to a product/variation.
 *
 * @api
 * @since 1.2
 *
 * @param int $product id of the product the download asset will be added to
 * @param string $file full or correct relative path to the download file asset.
 * @param int $variant id of the variant the download asset will be attached to.  For products with variants, this is a required parameter.
 * @return mixed false of failure, the new download asset id on success
 **/
function shopp_add_product_download($product, $file, $variant = false)
{
    if (empty($product) || empty($file)) {
        shopp_debug(__FUNCTION__ . ' failed: One or more missing parameters.');
        return false;
    }
    $File = new ProductDownload();
    $instore = $File->found($file);
    if (!$instore && (!is_file($file) || !is_readable($file))) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: File missing or unreadable.");
        return false;
    }
    $Product = new ShoppProduct($product);
    if (empty($Product->id)) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: No such product with id {$product}.");
        return false;
    }
    $Product->load_data(array('summary', 'prices'));
    if ("on" == $Product->variants && false === $variant) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: You must specify the variant id parameter for product {$product}.");
        return false;
    }
    $Price = reset($Product->prices);
    if (empty($Price->id)) {
        shopp_debug(__FUNCTION__ . " failed for file {$file}: Failed to load product variants.");
        return false;
    }
    if ($variant) {
        $Price = false;
        foreach ($Product->prices as $Price) {
            if ($variant == $Price->id) {
                break;
            }
        }
        if (false === $Price) {
            shopp_debug(__FUNCTION__ . " failed for file {$file}: You must specify a valid variant id parameter for product {$product}.");
            return false;
        }
    }
    // Save the uploaded file
    $File->load(array('type' => 'download', 'parent' => $Price->id));
    $File->parent = $Price->id;
    $File->context = "price";
    $File->type = "download";
    $File->name = basename($file);
    $File->filename = $File->name;
    if (!$instore) {
        $File->mime = file_mimetype($file, $File->name);
        $File->size = filesize($file);
        $File->store($file, 'file');
    } else {
        $File->uri = $file;
        $File->readmeta();
    }
    $File->save();
    if ($File->id) {
        return $File->id;
    }
    shopp_debug(__FUNCTION__ . " failed for file {$file}");
    return false;
}
开发者ID:forthrobot,项目名称:inuvik,代码行数:74,代码来源:asset.php

示例3: downloads

	/**
	 * AJAX behavior to process uploaded files intended as digital downloads
	 *
	 * Handles processing a file upload from a temporary file to a
	 * the correct storage container (DB, file system, etc)
	 *	 
	 * @return string JSON encoded result with DB id, filename, type & size
	 **/
	function downloads () {
		$error = false;
		if (isset($_FILES['Filedata']['error'])) $error = $_FILES['Filedata']['error'];
		if ($error) die(json_encode(array("error" => $this->uploadErrors[$error])));

		if (!is_uploaded_file($_FILES['Filedata']['tmp_name']))
			die(json_encode(array("error" => __('The file could not be saved because the upload was not found on the server.','Ecart'))));

		if (!is_readable($_FILES['Filedata']['tmp_name']))
			die(json_encode(array("error" => __('The file could not be saved because the web server does not have permission to read the upload.','Ecart'))));

		if ($_FILES['Filedata']['size'] == 0)
			die(json_encode(array("error" => __('The file could not be saved because the uploaded file is empty.','Ecart'))));

		// Save the uploaded file
		$File = new ProductDownload();
		$File->parent = 0;
		$File->context = "price";
		$File->type = "download";
		$File->name = $_FILES['Filedata']['name'];
		$File->filename = $File->name;
		$File->mime = file_mimetype($_FILES['Filedata']['tmp_name'],$File->name);
		$File->size = filesize($_FILES['Filedata']['tmp_name']);
		$File->store($_FILES['Filedata']['tmp_name'],'upload');
		$File->save();

		do_action('add_product_download',$File,$_FILES['Filedata']);

		echo json_encode(array("id"=>$File->id,"name"=>stripslashes($File->name),"type"=>$File->mime,"size"=>$File->size));
	}
开发者ID:robbiespire,项目名称:paQui,代码行数:38,代码来源:Warehouse.php


注:本文中的ProductDownload::store方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。