本文整理汇总了PHP中GenRandFileName函数的典型用法代码示例。如果您正苦于以下问题:PHP GenRandFileName函数的具体用法?PHP GenRandFileName怎么用?PHP GenRandFileName使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenRandFileName函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MoveAndUpdate
function MoveAndUpdate($CatId, $ImageFile, $FolderName)
{
$FileName = substr($ImageFile, 2);
$subDir = "";
// Determine the destination directory
//$randomDir = strtolower(chr(rand(65, 90)));
$subDir = $FolderName;
$destPath = realpath(ISC_BASE_PATH . '/' . 'category_images');
if (!is_dir($destPath . '/' . $subDir)) {
if (!mkdir($destPath . '/' . $subDir, 0777)) {
$subDir = '';
}
}
$destFile = GenRandFileName($FileName, 'cat');
$destPath = $destPath . '/' . $subDir . '/' . $destFile;
$returnPath = $subDir . '/' . $destFile;
//echo ISC_BASE_PATH.'/' . 'product_images'. '/' .$ImageFile;
if (file_exists(ISC_BASE_PATH . '/' . 'product_images' . '/' . $ImageFile)) {
if (copy(ISC_BASE_PATH . '/' . 'product_images' . '/' . $ImageFile, $destPath)) {
$query2 = "UPDATE isc_categories SET catimagefile='{$returnPath}' WHERE categoryid ='{$CatId}'";
$result2 = $GLOBALS['ISC_CLASS_DB']->Query($query2);
return true;
}
}
}
示例2: SaveQValueAssociationImage
private function SaveQValueAssociationImage()
{
if (!array_key_exists('associationimage', $_FILES) || $_FILES['associationimage']['error'] !== 0 || strtolower(substr($_FILES['associationimage']['type'], 0, 6)) !== 'image/') {
return false;
}
// Attempt to set the memory limit
setImageFileMemLimit($_FILES['associationimage']['tmp_name']);
// Generate the destination path
$randomDir = strtolower(chr(rand(65, 90)));
$destPath = realpath(ISC_BASE_PATH . '/' . GetConfig('ImageDirectory'));
if (!is_dir($destPath . '/' . $randomDir)) {
if (!@mkdir($destPath . '/' . $randomDir, 0777)) {
$randomDir = '';
}
}
$destFile = GenRandFileName($_FILES['associationimage']['name'], 'category');
$destPath = $destPath . '/' . $randomDir . '/' . $destFile;
$returnPath = $randomDir . '/' . $destFile;
$tmp = explode('.', $_FILES['associationimage']['name']);
$ext = strtolower($tmp[count($tmp) - 1]);
if ($ext == 'jpg') {
$srcImg = imagecreatefromjpeg($_FILES['associationimage']['tmp_name']);
} else {
if ($ext == 'gif') {
$srcImg = imagecreatefromgif($_FILES['associationimage']['tmp_name']);
if (!function_exists('imagegif')) {
$gifHack = 1;
}
} else {
$srcImg = imagecreatefrompng($_FILES['associationimage']['tmp_name']);
}
}
$srcWidth = imagesx($srcImg);
$srcHeight = imagesy($srcImg);
$widthLimit = GetConfig('BrandImageWidth');
$heightLimit = GetConfig('BrandImageHeight');
// If the image is small enough, simply move it and leave it as is
if ($srcWidth <= $widthLimit && $srcHeight <= $heightLimit) {
imagedestroy($srcImg);
move_uploaded_file($_FILES['associationimage']['tmp_name'], $destPath);
return $returnPath;
}
// Otherwise, the image needs to be resized
$attribs = getimagesize($_FILES['associationimage']['tmp_name']);
$width = $attribs[0];
$height = $attribs[1];
if ($width > $widthLimit) {
$height = ceil($widthLimit / $width * $height);
$width = $widthLimit;
}
if ($height > $heightLimit) {
$width = ceil($heightLimit / $height * $width);
$height = $heightLimit;
}
$dstImg = imagecreatetruecolor($width, $height);
if ($ext == "gif" && !isset($gifHack)) {
$colorTransparent = imagecolortransparent($srcImg);
imagepalettecopy($srcImg, $dstImg);
imagecolortransparent($dstImg, $colorTransparent);
imagetruecolortopalette($dstImg, true, 256);
} else {
if ($ext == "png") {
ImageColorTransparent($dstImg, ImageColorAllocate($dstImg, 0, 0, 0));
ImageAlphaBlending($dstImg, false);
}
}
imagecopyresampled($dstImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
if ($ext == "jpg") {
imagejpeg($dstImg, $destPath, 100);
} else {
if ($ext == "gif") {
if (isset($gifHack) && $gifHack == true) {
$thumbFile = isc_substr($destPath, 0, -3) . "jpg";
imagejpeg($dstImg, $destPath, 100);
} else {
imagegif($dstImg, $destPath);
}
} else {
imagepng($dstImg, $destPath);
}
}
@imagedestroy($dstImg);
@imagedestroy($srcImg);
@unlink($_FILES['associationimage']['tmp_name']);
// Change the permissions on the thumbnail file
isc_chmod($returnPath, ISC_WRITEABLE_FILE_PERM);
return $returnPath;
}
示例3: DownloadVideo
private function DownloadVideo($url, $FileType = FT_VIDEO)
{
include ISC_BASE_PATH . "/livevideos/phptube.php";
include ISC_BASE_PATH . "/livevideos/functions.php";
@clearstatcache();
@ini_set('output_buffering', 'off');
// output buffer fix
@ini_set('max_execution_time', 0);
// time limit fix
@ini_set('memory_limit', '1024M');
// memory problem fix
//error_reporting(1);
@ignore_user_abort(1);
@set_time_limit(0);
//@ob_end_clean();
@ob_implicit_flush(TRUE);
$pattern = getPatternFromUrl($url);
if ($FileType == FT_INSVIDEO) {
$dir = GetConfig('InstallVideoDirectory');
} else {
$dir = GetConfig('VideoDirectory');
}
if (is_dir(sprintf("../%s", $dir))) {
// Images and downloads will be stored within a directory randomly chosen from a-z.
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir("../" . $dir . "/" . $randomDir)) {
if (!@mkdir("../" . $dir . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
}
$patternName = $pattern . ".flv";
//
$randomFileName = GenRandFileName($patternName);
$fileName = $randomDir . "/" . $randomFileName;
$dest = realpath(ISC_BASE_PATH . "/" . $dir);
while (file_exists($dest . "/" . $fileName)) {
$fileName = basename($randomFileName);
$fileName = substr_replace($randomFileName, "-" . rand(0, 10000000000.0), strrpos($randomFileName, "."), 0);
$fileName = $randomDir . "/" . $fileName;
}
$dest .= "/" . $fileName;
$tube = new PHPTube();
$flv_http_path = $tube->download($pattern);
$data = file_get_contents($flv_http_path);
file_put_contents($dest, $data);
return $fileName;
if (filesize($dest) > 0) {
return $fileName;
} else {
return "failed";
}
}
示例4: _ImportRecord
//.........这里部分代码省略.........
}
// Overriding existing products, set the product id
if (isset($this->ImportSession['OverrideDuplicates']) && $this->ImportSession['OverrideDuplicates'] == 1) {
$productId = $existing['productid'];
//$cats = null; // blessen
//$cats = ""; let the category change in re-import blessen 22-10 as per client req.
if ($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() != $existing['prodvendorid']) {
$this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record']) . " " . GetLang('ImportProductInvalidVendor');
return;
}
$this->ImportSession['Results']['Updates'][] = $record['prodcode'];
} else {
//$this->ImportSession['Results']['Duplicates'][] = $record['prodcode'];
++$this->ImportSession['Results']['Imported'];
return;
}
}
// Do we have a product file? We need to deal with it now damn it!
if (isset($record['prodfile']) && $record['prodfile'] != '') {
// Is this a remote file?
$downloadDirectory = ISC_BASE_PATH . "/" . GetConfig('DownloadDirectory');
if (isc_substr(isc_strtolower($record['prodfile']), 0, 7) == "http://") {
// Need to fetch the remote file
$file = PostToRemoteFileAndGetResponse($record['prodfile']);
if ($file) {
// Place it in our downloads directory
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir($downloadDirectory . $randomDir)) {
if (!@mkdir($downloadDirectory . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName(basename($record['prodfile']));
if (!@file_put_contents($downloadDirectory . "/" . $fileName, $file)) {
$this->ImportSession['Results']['Warnings'][] = $record['prodcode'] . GetLang('ImportProductFileUnableToMove');
} else {
$productFiles[] = array("prodhash" => "", "downfile" => $fileName, "downdateadded" => time(), "downmaxdownloads" => 0, "downexpiresafter" => 0, "downfilesize" => filesize($downloadDirectory . "/" . $fileName), "downname" => basename($record['prodfile']), "downdescription" => "");
}
} else {
$this->ImportSession['Results']['Warnings'][] = $record['prodcode'] . GetLang('ImportProductFileDoesntExist');
}
} else {
// This file exists, can be imported
if (file_exists($downloadDirectory . "/import/" . $record['prodfile'])) {
// Move it to our images directory
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir("../" . $downloadDirectory . "/" . $randomDir)) {
if (!@mkdir($downloadDirectory . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName($record['prodfile']);
if (!@copy($downloadDirectory . "/import/" . $record['prodfile'], $downloadDirectory . "/" . $fileName)) {
$this->ImportSession['Results']['Warnings'][] = $record['prodcode'] . GetLang('ImportProductFileUnableToMove');
} else {
$productFiles[] = array("prodhash" => "", "downfile" => $fileName, "downdateadded" => time(), "downmaxdownloads" => 0, "downexpiresafter" => 0, "downfilesize" => filesize($downloadDirectory . "/" . $fileName), "downname" => basename($record['prodfile']), "downdescription" => "");
}
} else {
$this->ImportSession['Results']['Warnings'][] = $record['prodcode'] . GetLang('ImportProductFileDoesntExist');
}
}
}
// Do we have an image? We need to deal with it before we do anything else
$productImages = array();
示例5: CommitWrap
/**
* Commit a gift wrapping type to the database (either create a new one or update an existing one)
*
* @param array An array of data about the gift wrapping type.
* @param int If updating an existing wrap, the ID.
* @return boolean True if successful, false if not.
*/
private function CommitWrap($data, $wrapId = 0)
{
if (!isset($data['wrapvisible'])) {
$data['wrapvisible'] = 0;
}
if (!isset($data['wrapallowcomments'])) {
$data['wrapallowcomments'] = '';
}
if (isset($_FILES['wrapimage']) && is_array($_FILES['wrapimage']) && $_FILES['wrapimage']['name'] != '') {
// Clean up the incoming file name a bit
$_FILES['wrapimage']['name'] = preg_replace("#[^\\w.]#i", "_", $_FILES['wrapimage']['name']);
$_FILES['wrapimage']['name'] = preg_replace("#_{1,}#i", "_", $_FILES['wrapimage']['name']);
$randomFileName = GenRandFileName($_FILES['wrapimage']['name']);
$imageLocation = 'wrap_images/' . $randomFileName;
$dest = ISC_BASE_PATH . '/' . GetConfig('ImageDirectory') . '/' . $imageLocation;
if (move_uploaded_file($_FILES['wrapimage']['tmp_name'], $dest)) {
isc_chmod($dest, ISC_WRITEABLE_FILE_PERM);
$data['wrappreview'] = $imageLocation;
}
}
$wrapData = array('wrapname' => $data['wrapname'], 'wrapprice' => DefaultPriceFormat($data['wrapprice']), 'wrapvisible' => (int) $data['wrapvisible'], 'wrapallowcomments' => (int) $data['wrapallowcomments']);
if (isset($data['wrappreview'])) {
$wrapData['wrappreview'] = $data['wrappreview'];
}
if ($wrapId == 0) {
$wrapId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('gift_wrapping', $wrapData);
} else {
$GLOBALS['ISC_CLASS_DB']->UpdateQuery('gift_wrapping', $wrapData, "wrapid='" . (int) $wrapId . "'");
}
$GLOBALS['ISC_CLASS_DATA_STORE']->UpdateGiftWrapping();
// Couldn't save? return an error message
if ($GLOBALS['ISC_CLASS_DB']->GetErrorMsg()) {
return false;
}
return true;
}
示例6: ValidateWrap
/**
* Validate the passed input for a gift wrapping type for errors.
*
* @param array An array of data about the gift wrapping type.
* @param string An error message (if any) from validation errors (on return false - by reference)
* @return boolean True if successful, false if not.
*/
private function ValidateWrap($data, &$error)
{
$requiredFields = array(
'wrapname' => GetLang('EnterGiftWrapName'),
'wrapprice' => GetLang('EnterGiftWrapPrice')
);
foreach($requiredFields as $field => $message) {
if(!isset($data[$field]) || trim($data[$field]) == '') {
$error = $message;
return false;
}
}
// Does a wrapping type exist with the same name?
$wrapIdQuery = '';
if(isset($data['wrapId']) && $data['wrapId'] > 0) {
$wrapIdQuery = " AND wrapid!='".(int)$data['wrapId']."'";
}
// Check that a duplicate wrapping type doesn't exist with this name
$query = "
SELECT wrapid
FROM [|PREFIX|]gift_wrapping
WHERE wrapname='".$GLOBALS['ISC_CLASS_DB']->Quote($data['wrapname'])."'".$wrapIdQuery;
// if an image was uploaded, validate that
try {
$files = ISC_UPLOADHANDLER::getUploadedFiles();
foreach ($files as /** @var UploadHandlerFile */$file) {
if ($file->fieldName == 'wrapimage') {
$dest = ISC_BASE_PATH . '/' . GetConfig('ImageDirectory') . '/wrap_images/' . GenRandFileName($file->name);
$file->moveAs($dest);
$image = @getimagesize($dest);
if ($image === false) {
unlink($dest);
$error = GetLang("WrapImageInvalid");
return false;
}
isc_chmod($dest, ISC_WRITEABLE_FILE_PERM);
break;
}
}
} catch (UploadHandlerException $exception) {
$error = $exception->getMessage();
return false;
}
if($GLOBALS['ISC_CLASS_DB']->FetchOne($query)) {
$error = GetLang('DuplicateGiftWrapName');
return false;
}
// Otherwise it's valid
return true;
}
示例7: ProcessImg
protected function ProcessImg()
{
$sql = "select * from [|PREFIX|]import_products where flag=0 order by tempid asc";
$query = $GLOBALS['ISC_CLASS_DB']->Query($sql);
while ($record = $GLOBALS['ISC_CLASS_DB']->Fetch($query)) {
// Do we have a product file? We need to deal with it now damn it!
if (isset($record['product_file']) && $record['product_file'] != '') {
// Is this a remote file?
$downloadDirectory = ISC_BASE_PATH . "/" . GetConfig('DownloadDirectory');
if (isc_substr(isc_strtolower($record['product_file']), 0, 7) == "http://") {
// Need to fetch the remote file
$file = PostToRemoteFileAndGetResponse($record['product_file']);
if ($file) {
// Place it in our downloads directory
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir($downloadDirectory . $randomDir)) {
if (!@mkdir($downloadDirectory . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName(basename($record['product_file']));
if (!@file_put_contents($downloadDirectory . "/" . $fileName, $file)) {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductFileUnableToMove');
} else {
$productFiles[] = array("prodhash" => "", "downfile" => $fileName, "downdateadded" => time(), "downmaxdownloads" => 0, "downexpiresafter" => 0, "downfilesize" => filesize($downloadDirectory . "/" . $fileName), "downname" => basename($record['product_file']), "downdescription" => "");
}
} else {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductFileDoesntExist');
}
} else {
// This file exists, can be imported
if (file_exists($downloadDirectory . "/import/" . $record['product_file'])) {
// Move it to our images directory
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir("../" . $downloadDirectory . "/" . $randomDir)) {
if (!@mkdir($downloadDirectory . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName($record['product_file']);
if (!@copy($downloadDirectory . "/import/" . $record['product_file'], $downloadDirectory . "/" . $fileName)) {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductFileUnableToMove');
} else {
$productFiles[] = array("prodhash" => "", "downfile" => $fileName, "downdateadded" => time(), "downmaxdownloads" => 0, "downexpiresafter" => 0, "downfilesize" => filesize($downloadDirectory . "/" . $fileName), "downname" => basename($record['product_file']), "downdescription" => "");
}
} else {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductFileDoesntExist');
}
}
}
// Do we have an image? We need to deal with it before we do anything else
$productImages = array();
if (isset($record['product_images']) && $record['product_images'] != '') {
// Is this a remote file?
$imageDirectory = ISC_BASE_PATH . "/" . GetConfig('ImageDirectory');
if (isc_substr(isc_strtolower($record['product_images']), 0, 7) == "http://") {
// Need to fetch the remote file
$image_pieces = preg_split("/[;,]/", $record['product_images']);
$end = end($image_pieces);
if (empty($end)) {
array_pop($image_pieces);
}
foreach ($image_pieces as $key => $value) {
$temp_key = $key + 1;
$image = PostToRemoteFileAndGetResponse($value);
if ($image) {
// Place it in our images directory
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir($imageDirectory . "/" . $randomDir)) {
if (!@mkdir($imageDirectory . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName(basename($value));
if (!@file_put_contents($imageDirectory . "/" . $fileName, $image)) {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductImageUnableToMove');
} else {
if (!is_array(@getimagesize($imageDirectory . "/" . $fileName))) {
@unlink($imageDirectory . "/" . $fileName);
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductImageInvalidFile');
} else {
$thumbName = $GLOBALS['ISC_CLASS_ADMIN_PRODUCT']->_AutoGenerateThumb($fileName, "large");
$productImages[] = array("imagefile" => $thumbName, "imageisthumb" => 0, "imagesort" => $temp_key);
if ($hasThumb == false) {
if ($key == 0) {
$thumbName = $GLOBALS['ISC_CLASS_ADMIN_PRODUCT']->_AutoGenerateThumb($fileName);
if ($thumbName) {
$productImages[] = array("imagefile" => $thumbName, "imageisthumb" => 1, "imagesort" => 0);
} else {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductImageCorrupt');
}
$tinyName = $GLOBALS['ISC_CLASS_ADMIN_PRODUCT']->_AutoGenerateThumb($fileName, "tiny");
if ($tinyName) {
$productImages[] = array("imagefile" => $tinyName, "imageisthumb" => 2, "imagesort" => 0);
} else {
$this->ImportSession['Results']['Warnings'][] = $record['partnumber'] . GetLang('ImportProductImageCorrupt');
}
//.........这里部分代码省略.........
示例8: build_series_path
function build_series_path($prefix, $FileName, $Append = "")
{
require_once LOCAL_LIB . 'general.php';
$FileName = $prefix . '__' . $FileName;
return GenRandFileName($FileName, $Append);
}
示例9: _StoreCSVfile
public function _StoreCSVfile($FileName)
{
$dir = "ymmfiles";
$MsgStatus = "";
if (is_array($_FILES[$FileName]) && $_FILES[$FileName]['name'] != "") {
if (isc_strtolower(isc_substr($_FILES[$FileName]['name'], -3)) != "csv") {
echo $GLOBALS['Message'] = MessageBox("Please upload a csv file as YMM data", $MsgStatus);
return "";
}
if (!is_dir(sprintf("../%s", $dir))) {
@mkdir("../" . $dir, 0777);
}
// Clean up the incoming file name a bit
$_FILES[$FileName]['name'] = preg_replace("#[^\\w.]#i", "_", $_FILES[$FileName]['name']);
$_FILES[$FileName]['name'] = preg_replace("#_{1,}#i", "_", $_FILES[$FileName]['name']);
$randomFileName = GenRandFileName($_FILES[$FileName]['name']);
$dest = realpath(ISC_BASE_PATH . "/" . $dir);
$dest .= "/" . $randomFileName;
if (move_uploaded_file($_FILES[$FileName]["tmp_name"], $dest)) {
isc_chmod($dest, ISC_WRITEABLE_FILE_PERM);
// The file was moved successfully
return $randomFileName;
} else {
// Couldn't move the file, maybe the directory isn't writable?
return "";
}
} else {
// The file doesn't exist in the $_FILES array
return "";
}
}
示例10: DownloadMagnaflow
/**
* @desc : Used for Magnaflow videos and other files also
* @url : File URL
* @FileType : table name of the file
*/
private function DownloadMagnaflow($url, $FileType = "product_videos")
{
@clearstatcache();
@ini_set('output_buffering', 'off');
// output buffer fix
@ini_set('max_execution_time', 0);
// time limit fix
@ini_set('memory_limit', '1024M');
// memory problem fix
error_reporting(1);
@ignore_user_abort(1);
@set_time_limit(0);
//@ob_end_clean();
//@ob_implicit_flush(TRUE);
if ($FileType == "product_videos") {
$dir = GetConfig('VideoDirectory');
} else {
if ($FileType == "install_videos") {
$dir = GetConfig('InstallVideoDirectory');
} else {
if ($FileType == "audio_clips") {
$dir = "audio_clips";
} else {
if ($FileType == "instruction_files") {
$dir = "instruction_file";
} else {
if ($FileType == "article_files") {
$dir = "article_file";
}
}
}
}
}
//$patternName = "magnaflow.swf";
$patternName = substr($url, strrpos($url, "/") + 1);
$randomFileName = GenRandFileName($patternName);
if ($FileType == "product_videos" || $FileType == "install_videos") {
if (is_dir(sprintf(ISC_BASE_PATH . "/" . "%s", $dir))) {
// Images and downloads will be stored within a directory randomly chosen from a-z.
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir(ISC_BASE_PATH . "/" . $dir . "/" . $randomDir)) {
if (!@mkdir(ISC_BASE_PATH . "/" . $dir . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
}
$fileName = $randomDir . "/" . $randomFileName;
$dest = realpath(ISC_BASE_PATH . "/" . $dir);
while (file_exists($dest . "/" . $fileName)) {
$fileName = basename($randomFileName);
$fileName = substr_replace($randomFileName, "-" . rand(0, 10000000000.0), strrpos($randomFileName, "."), 0);
$fileName = $randomDir . "/" . $fileName;
}
} else {
//if($FileType == "audio_clips" || $FileType == "instruction_files") for else if
$fileName = $randomFileName;
$dest = realpath(ISC_BASE_PATH . "/" . $dir);
while (file_exists($dest . "/" . $fileName)) {
$fileName = basename($randomFileName);
$fileName = substr_replace($randomFileName, "-" . rand(0, 10000000000.0), strrpos($randomFileName, "."), 0);
$fileName = $fileName;
}
}
$dest .= "/" . $fileName;
ini_set("display_errors", 1);
$flv_http_path = $url;
$data = file_get_contents($flv_http_path);
file_put_contents($dest, $data);
if (filesize($dest) > 1 * 1024) {
return $fileName;
} else {
return "failed";
}
}
示例11: _ImportFile
private function _ImportFile($record, $index = '')
{
$productFileName = $record['prodfile' . $index];
$fileDescription = '';
if (!empty($record['prodfiledescription' . $index])) {
$fileDescription = $record['prodfiledescription' . $index];
}
$fileMaxDownloads = 0;
if (!empty($record['prodfilemaxdownloads' . $index])) {
$fileMaxDownloads = (int)$record['prodfilemaxdownloads' . $index];
}
$fileExpiresAfter = 0;
if (!empty($record['prodfileexpiresafter' . $index])) {
if (preg_match('/([0-9]+) (days|weeks|months|years)/i', $record['prodfileexpiresafter' . $index], $matches)) {
$quantity = $matches[1];
$unit = strtolower($matches[2]);
switch ($unit) {
case 'days':
$fileExpiresAfter = 86400 * $quantity;
break;
case 'weeks':
$fileExpiresAfter = 604800 * $quantity;
break;
case 'months':
$fileExpiresAfter = 2592000 * $quantity; //assumed to be 30 days, as per class.product.php
break;
case 'years':
$fileExpiresAfter = 31536000 * $quantity;
break;
}
}
}
$productFile = false;
// Is this a remote file?
$downloadDirectory = ISC_BASE_PATH."/".GetConfig('DownloadDirectory');
if(isc_substr(isc_strtolower($productFileName), 0, 7) == "http://") {
// Need to fetch the remote file
$file = PostToRemoteFileAndGetResponse($productFileName);
if($file) {
// Place it in our downloads directory
$randomDir = strtolower(chr(rand(65, 90)));
if(!is_dir($downloadDirectory.$randomDir)) {
if(!isc_mkdir($downloadDirectory."/".$randomDir)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName(basename($productFileName));
if(!@file_put_contents($downloadDirectory."/".$fileName, $file)) {
$this->ImportSession['Results']['Warnings'][] = $record['prodname'].GetLang('ImportProductFileUnableToMove');
}
else {
$productFile = array(
"prodhash" => "",
"downfile" => $fileName,
"downdateadded" => time(),
"downmaxdownloads" => $fileMaxDownloads,
"downexpiresafter" => $fileExpiresAfter,
"downfilesize" => filesize($downloadDirectory."/".$fileName),
"downname" => basename($productFileName),
"downdescription" => $fileDescription
);
}
}
else {
$this->ImportSession['Results']['Warnings'][] = $record['prodname'].GetLang('ImportProductFileDoesntExist');
}
}
// Treating the file as a local file, in the product_fules/import directory
else {
// This file exists, can be imported
if(file_exists($downloadDirectory."/import/".$productFileName)) {
// Move it to our images directory
$randomDir = strtolower(chr(rand(65, 90)));
if(!is_dir("../".$downloadDirectory."/".$randomDir)) {
if(!isc_mkdir($downloadDirectory."/".$randomDir)) {
$randomDir = '';
}
}
// Generate a random filename
$fileName = $randomDir . "/" . GenRandFileName($productFileName);
if(!@copy($downloadDirectory."/import/".$productFileName, $downloadDirectory."/".$fileName)) {
$this->ImportSession['Results']['Warnings'][] = $record['prodname'].GetLang('ImportProductFileUnableToMove');
}
else {
$productFile = array(
"prodhash" => "",
"downfile" => $fileName,
"downdateadded" => time(),
"downmaxdownloads" => $fileMaxDownloads,
"downexpiresafter" => $fileExpiresAfter,
//.........这里部分代码省略.........
示例12: _StoreFileAndReturnId
public function _StoreFileAndReturnId($FileName)
{
// This function takes a file name as its arguement and stores
// this file in the /downloads or /images directory depending
// on the $FileType enumeration value
$dir = "series_images";
if (is_array($_FILES[$FileName]) && $_FILES[$FileName]['name'] != "") {
// If it's an image, make sure it's a valid image type
if (isc_strtolower(isc_substr($_FILES[$FileName]['type'], 0, 5)) != "image") {
return "";
}
if (is_dir(sprintf("../%s", $dir))) {
// Clean up the incoming file name a bit
$_FILES[$FileName]['name'] = preg_replace("#[^\\w.]#i", "_", $_FILES[$FileName]['name']);
$_FILES[$FileName]['name'] = preg_replace("#_{1,}#i", "_", $_FILES[$FileName]['name']);
$randomFileName = GenRandFileName($_FILES[$FileName]['name']);
$fileName = $randomFileName;
$dest = realpath(ISC_BASE_PATH . "/" . $dir);
while (file_exists($dest . "/" . $fileName)) {
$fileName = basename($randomFileName);
$fileName = substr_replace($randomFileName, "-" . rand(0, 10000000000.0), strrpos($randomFileName, "."), 0);
$fileName = $randomDir . "/" . $fileName;
}
$dest .= "/" . $fileName;
if (move_uploaded_file($_FILES[$FileName]["tmp_name"], $dest)) {
isc_chmod($dest, ISC_WRITEABLE_FILE_PERM);
// The file was moved successfully
return $fileName;
} else {
// Couldn't move the file, maybe the directory isn't writable?
return "";
}
} else {
// The directory doesn't exist
return "";
}
} else {
// The file doesn't exist in the $_FILES array
return "";
}
}
示例13: InsertProduct
//.........这里部分代码省略.........
$product = array("importproductid" => $productId, "prodname" => $productData['prodname'], "prodtype" => (int) $productData['prodtype'], "prodcode" => $productData['prodcode'], "proddesc" => $productData['proddesc'], "prodsearchkeywords" => $productData['prodsearchkeywords'], "prodavailability" => $productData['prodavailability'], "prodprice" => (double) $productData['prodprice'], "prodcostprice" => (double) $productData['prodcostprice'], "prodretailprice" => (double) $productData['prodretailprice'], "prodsaleprice" => (double) $productData['prodsaleprice'], "prodcalculatedprice" => (double) $calculatedPrice, "prodsortorder" => (int) $productData['prodsortorder'], "prodvisible" => $productData['prodvisible'], "prodfeatured" => $productData['prodfeatured'], "prodrelatedproducts" => $productData['prodrelatedproducts'], "prodcurrentinv" => (int) $productData['prodcurrentinv'], "prodlowinv" => (int) $productData['prodlowinv'], "prodoptionsrequired" => $productData['prodoptionsrequired'], "prodwarranty" => $productData['prodwarranty'], "prodweight" => (double) $productData['prodweight'], "prodwidth" => (double) $productData['prodwidth'], "prodheight" => (double) $productData['prodheight'], "proddepth" => (double) $productData['proddepth'], "prodfixedshippingcost" => (double) $productData['prodfixedshippingcost'], "prodfreeshipping" => $productData['prodfreeshipping'], "prodinvtrack" => $productData['prodinvtrack'], "prodratingtotal" => 0, "prodnumratings" => 0, "prodnumsold" => (int) $productData['prodnumsold'], "proddateadded" => (int) $productData['proddateadded'], "prodbrandid" => $brandId, "prodnumviews" => (int) $productData['prodnumviews'], "prodmetakeywords" => $productData['prodmetakeywords'], "prodmetadesc" => $productData['prodmetadesc'], "prodcatids" => $prodCatsCSV, "prodmyobasset" => '', "prodmyobincome" => '', "prodmyobexpense" => '', "prodpeachtreegl" => '');
$productId = $this->ConvertedInsertQuery("products", $product);
if (!$productId) {
$err = "Failed to insert product (DEBUG)";
$this->_LogImportError('invalid', $err);
return false;
}
// Insert any category associations
foreach ($prodCats as $categoryId) {
$association = array("productid" => $productId, "categoryid" => $categoryId);
$this->ConvertedInsertQuery("categoryassociations", $association);
}
// Are there any product images that need to be inserted?
$has_thumb = false;
$has_tiny = false;
$thumb_file = '';
$tiny_file = '';
$firstImage = '';
if (is_array($productData['images'])) {
$GLOBALS['ISC_CLASS_ADMIN_PRODUCT'] = GetClass('ISC_ADMIN_PRODUCT');
foreach ($productData['images'] as $k => $image) {
// Only copy across product images that exist
if (isset($image['imagefile']) && !file_exists($image['imagefile'])) {
continue;
}
// Copy the file across to the store
$randomDir = strtolower(chr(rand(65, 90)));
if (!is_dir(ISC_BASE_PATH . "/" . GetConfig('ImageDirectory') . "/" . $randomDir)) {
if (!@mkdir(ISC_BASE_PATH . "/" . GetConfig('ImageDirectory') . "/" . $randomDir, 0777)) {
$randomDir = '';
}
}
if (isset($image['imagedata']) && $image['imagedata'] !== '') {
$fileName = $randomDir . "/" . GenRandFileName($image['imagefilename']);
} else {
$fileName = $randomDir . "/" . GenRandFileName(basename($image['imagefile']));
}
$dest = ISC_BASE_PATH . "/" . GetConfig('ImageDirectory');
$dest .= "/" . $fileName;
if (isset($image['imagedata']) && $image['imagedata'] !== '') {
file_put_contents($dest, $image['imagedata']);
} else {
copy($image['imagefile'], $dest);
}
// Is this image supposed to be a thumbnail?
if (isset($image['imageisthumb']) && $image['imageisthumb'] == 1) {
if (!$has_thumb) {
$has_thumb = true;
$thumb_file = $fileName;
}
continue;
}
// Is this image supposed to be a tiny version?
if (isset($image['imageisthumb']) && $image['imageisthumb'] == 2) {
if (!$has_tiny) {
$has_tiny = true;
$tiny_file = $fileName;
}
continue;
}
if ($firstImage == '') {
$firstImage = $fileName;
}
// A normal product image
$newImage = array("imageprodid" => $productId, "imagefile" => $fileName, "imageisthumb" => $image['imageisthumb'], "imagesort" => $k + 1);
$this->ConvertedInsertQuery("product_images", $newImage);