本文整理汇总了PHP中ProductDownload::_engine方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductDownload::_engine方法的具体用法?PHP ProductDownload::_engine怎么用?PHP ProductDownload::_engine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductDownload
的用法示例。
在下文中一共展示了ProductDownload::_engine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: substr
//.........这里部分代码省略.........
foreach($_POST['price'] as $i => $option) {
if (empty($option['id'])) {
$Price = new Price();
$option['product'] = $Product->id;
} else $Price = new Price($option['id']);
$option['sortorder'] = array_search($i,$_POST['sortorder'])+1;
// Remove VAT amount to save in DB
if ($base['vat'] && isset($option['tax']) && $option['tax'] == "on") {
$option['price'] = (floatvalue($option['price'])/(1+$taxrate));
$option['saleprice'] = (floatvalue($option['saleprice'])/(1+$taxrate));
}
$option['shipfee'] = floatvalue($option['shipfee']);
$option['weight'] = floatvalue($option['weight']);
if (isset($options['dimensions']) && is_array($options['dimensions']))
foreach ($option['dimensions'] as &$dimension)
$dimension = floatvalue($dimension);
$Price->updates($option);
$Price->save();
if (!empty($option['download'])) $Price->attach_download($option['download']);
if (!empty($option['downloadpath'])) { // Attach file specified by URI/path
if (!empty($Price->download->id) || (empty($Price->download) && $Price->load_download())) {
$File = $Price->download;
} else $File = new ProductDownload();
$stored = false;
$tmpfile = sanitize_path($option['downloadpath']);
$File->storage = false;
$Engine = $File->_engine(); // Set engine from storage settings
$File->parent = $Price->id;
$File->context = "price";
$File->type = "download";
$File->name = !empty($option['downloadfile'])?$option['downloadfile']:basename($tmpfile);
$File->filename = $File->name;
if ($File->found($tmpfile)) {
$File->uri = $tmpfile;
$stored = true;
} else $stored = $File->store($tmpfile,'file');
if ($stored) {
$File->readmeta();
$File->save();
}
} // END attach file by path/uri
}
unset($Price);
}
// No variation options at all, delete all variation-pricelines
if (!empty($Product->prices) && is_array($Product->prices)
&& (empty($_POST['options']['v']) || empty($_POST['options']['a']))) {
foreach ($Product->prices as $priceline) {
// Skip if not tied to variation options
if ($priceline->optionkey == 0) continue;
if ((empty($_POST['options']['v']) && $priceline->context == "variation")
|| (empty($_POST['options']['a']) && $priceline->context == "addon")) {
$Price = new Price($priceline->id);
$Price->delete();
示例2: array
function import_file () {
check_admin_referer('wp_ajax_ecart_import_file');
global $Ecart;
$Engine =& $Ecart->Storage->engines['download'];
$error = create_function('$s', 'die(json_encode(array("error" => $s)));');
if (empty($_REQUEST['url'])) $error(__('No file import URL was provided.','Ecart'));
$url = $_REQUEST['url'];
$request = parse_url($url);
$headers = array();
$filename = basename($request['path']);
$_ = new StdClass();
$_->name = $filename;
$_->stored = false;
$File = new ProductDownload();
$stored = false;
$File->_engine(); // Set engine from storage settings
$File->uri = sanitize_path($url);
$File->type = "download";
$File->name = $filename;
$File->filename = $filename;
if ($File->found()) {
// File in storage, look up meta from storage engine
$File->readmeta();
$_->stored = true;
$_->path = $File->uri;
$_->size = $File->size;
$_->mime = $File->mime;
if ($_->mime == "application/octet-stream" || $_->mime == "text/plain")
$mime = file_mimetype($File->name);
if ($mime == "application/octet-stream" || $mime == "text/plain")
$_->mime = $mime;
} else {
if (!$importfile = @tempnam(sanitize_path(realpath(ECART_TEMP_PATH)), 'shp')) $error(sprintf(__('A temporary file could not be created for importing the file.','Ecart'),$importfile));
if (!$incoming = @fopen($importfile,'w')) $error(sprintf(__('A temporary file at %s could not be opened for importing.','Ecart'),$importfile));
if (!$file = @fopen(linkencode($url), 'rb')) $error(sprintf(__('The file at %s could not be opened for importing.','Ecart'),$url));
$data = @stream_get_meta_data($file);
if (isset($data['timed_out']) && $data['timed_out']) $error(__('The connection timed out while trying to get information about the target file.','Ecart'));
if (isset($data['wrapper_data'])) {
foreach ($data['wrapper_data'] as $d) {
if (strpos($d,':') === false) continue;
list($name,$value) = explode(': ',$d);
if ($rel = strpos($value,';')) $headers[$name] = substr($value,0,$rel);
else $headers[$name] = $value;
}
}
$tmp = basename($importfile);
$Settings =& EcartSettings();
$_->path = $importfile;
if (empty($headers)) {
// Stat file data directly if no stream data available
$_->size = filesize($url);
$_->mime = file_mimetype($url);
} else {
// Use the stream data
$_->size = $headers['Content-Length'];
$_->mime = $headers['Content-Type'] == 'text/plain'?file_mimetype($_->name):$headers['Content-Type'];
}
}
// Mimetype must be set or we'll have problems in the UI
if (!$_->mime) $_->mime = "application/octet-stream";
ob_end_clean();
header("Connection: close");
header("Content-Encoding: none");
ob_start();
echo json_encode($_);
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();
ob_end_clean();
if ($_->stored) return;
$progress = 0;
fseek($file, 0);
$packet = 1024*1024;
while(!feof($file)) {
if (connection_status() !== 0) return false;
$buffer = fread($file,$packet);
if (!empty($buffer)) {
fwrite($incoming, $buffer);
$progress += strlen($buffer);
$Settings->save($tmp.'_import_progress',$progress);
}
}
fclose($file);
fclose($incoming);
//.........这里部分代码省略.........