예제 #1
0
	function meta ($uri) {
		$_ = array();
		$_['size'] = filesize(sanitize_path($this->path.'/'.$uri));
		$_['mime'] = file_mimetype(sanitize_path($this->path.'/'.$uri));
		return $_;
	}
 function product_downloads()
 {
     $error = false;
     if (isset($_FILES['Filedata']['error'])) {
         $error = $_FILES['Filedata']['error'];
     }
     if ($error) {
         die(json_encode(array("error" => $this->uploadErrors[$error])));
     }
     // Save the uploaded file
     $File = new Asset();
     $File->parent = 0;
     $File->context = "price";
     $File->datatype = "download";
     $File->name = $_FILES['Filedata']['name'];
     $File->size = filesize($_FILES['Filedata']['tmp_name']);
     $File->properties = array("mimetype" => file_mimetype($_FILES['Filedata']['tmp_name'], $File->name));
     $File->data = addslashes(file_get_contents($_FILES['Filedata']['tmp_name']));
     $File->save();
     unset($File->data);
     // Remove file contents from memory
     do_action('add_product_download', $File, $_FILES['Filedata']);
     echo json_encode(array("id" => $File->id, "name" => stripslashes($File->name), "type" => $File->properties['mimetype'], "size" => $File->size));
 }
예제 #3
0
파일: asset.php 프로젝트: forthrobot/inuvik
/**
 * 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;
}
예제 #4
0
	/**
	 * 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));
	}
예제 #5
0
} else {
    // 初期データを取得
    if (empty($_GET['id'])) {
        $_view['member'] = default_members();
    } else {
        $members = select_members(array('where' => array('members.id = :id', array('id' => $_GET['id']))), array('associate' => true));
        if (empty($members)) {
            warning('編集データが見つかりません。');
        } else {
            $_view['member'] = $members[0];
        }
    }
    if (isset($_GET['_type']) && $_GET['_type'] === 'json') {
        // 名簿情報を取得
        header('Content-Type: application/json; charset=' . MAIN_CHARSET);
        echo json_encode(array('status' => 'OK', 'data' => $_view, 'files' => array('image_01' => $_view['member']['image_01'] ? file_mimetype($_view['member']['image_01']) : null, 'image_02' => $_view['member']['image_02'] ? file_mimetype($_view['member']['image_02']) : null)));
        exit;
    } else {
        // 投稿セッションを初期化
        unset($_SESSION['post']);
        unset($_SESSION['file']);
    }
    // 編集開始日時を記録
    if (!empty($_GET['id'])) {
        $_SESSION['update']['member'] = localdate('Y-m-d H:i:s');
    }
}
if (empty($_POST['view']) || $_POST['view'] !== 'preview') {
    // 名簿の表示用データ作成
    $_view['member'] = view_members($_view['member']);
}
예제 #6
0
 /**
  * Gets the size and mimetype meta of a stored asset
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @param string $uri The URI for the resource
  * @param string $filename (optional) File name of the asset
  * @return array A named list of the stored file size and mimetype
  **/
 public function meta($uri = false, $filename = false)
 {
     $_ = array();
     if (empty($uri)) {
         return $_;
     }
     $file = sDB::query("SELECT LENGTH(data) AS size FROM {$this->_table} WHERE {$this->_key}='{$uri}' LIMIT 1");
     if ($file && isset($file->size)) {
         $_['size'] = $file->size;
     }
     if ($filename !== false) {
         $_['mime'] = file_mimetype(false, $filename);
     }
     return $_;
 }
예제 #7
0
파일: Ajax.php 프로젝트: msigley/shopp
 public function import_file()
 {
     check_admin_referer('wp_ajax_shopp_import_file');
     $Shopp = Shopp::object();
     $Engine =& $Shopp->Storage->engines['download'];
     $error = create_function('$s', 'die(json_encode(array("error" => $s)));');
     if (empty($_REQUEST['url'])) {
         $error(__('No file import URL was provided.', 'Shopp'));
     }
     $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(SHOPP_TEMP_PATH)), 'shp'))) {
             $error(sprintf(__('A temporary file could not be created for importing the file.', 'Shopp'), $importfile));
         }
         if (!($incoming = @fopen($importfile, 'w'))) {
             $error(sprintf(__('A temporary file at %s could not be opened for importing.', 'Shopp'), $importfile));
         }
         if (!($file = @fopen(linkencode($url), 'rb'))) {
             $error(sprintf(__('The file at %s could not be opened for importing.', 'Shopp'), $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.', 'Shopp'));
         }
         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 =& ShoppSettings();
         $_->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";
     }
     echo str_repeat(' ', 1024);
     // Minimum browser data
     echo '<script type="text/javascript">var importFile = ' . json_encode($_) . ';</script>' . "\n";
     echo '<script type="text/javascript">var importProgress = 0;</script>' . "\n";
     if ($_->stored) {
         exit;
     }
     @ob_flush();
     @flush();
     $progress = 0;
     $bytesread = 0;
     fseek($file, 0);
     $packet = 1024 * 1024;
     set_time_limit(0);
     // Prevent timeouts
     while (!feof($file)) {
         if (connection_status() !== 0) {
             return false;
         }
         $buffer = fread($file, $packet);
         if (!empty($buffer)) {
             fwrite($incoming, $buffer);
             $bytesread += strlen($buffer);
             echo '<script type="text/javascript">importProgress = ' . $bytesread / (int) $_->size . ';</script>' . "\n";
             @ob_flush();
             @flush();
         }
     }
     @ob_end_flush();
     fclose($file);
     fclose($incoming);
     exit;
 }
예제 #8
0
파일: file.php 프로젝트: refirio/levis
/**
 * Resize the file.
 *
 * @param string $original
 * @param string $output
 * @param int    $output_width
 * @param int    $output_height
 * @param int    $quality
 *
 * @return bool
 */
function file_resize($original, $output, $output_width, $output_height, $quality = 80)
{
    if (!regexp_match('\\.(gif|jpeg|jpg|jpe|png)$', $original)) {
        return true;
    }
    list($original_width, $original_height) = file_info($original);
    if ($original_width > $output_width) {
        $width = $output_width;
        $height = $width / $original_width * $original_height;
    } else {
        $width = $original_width;
        $height = $original_height;
    }
    if ($height > $output_height) {
        $width = $output_height / $height * $width;
        $height = $output_height;
    }
    if ($original_width === $width && $original_height === $height && $output === null) {
        header('Content-type: ' . file_mimetype($original));
        readfile($original);
        return true;
    }
    if (regexp_match('\\.gif$', $original)) {
        $file = imagecreatefromgif($original);
        $bgcolor = imagecolorallocatealpha($file, 0, 0, 0, 127);
    } elseif (regexp_match('\\.(jpeg|jpg|jpe)$', $original)) {
        $file = imagecreatefromjpeg($original);
        $bgcolor = false;
    } elseif (regexp_match('\\.png$', $original)) {
        $file = imagecreatefrompng($original);
        $bgcolor = imagecolorallocatealpha($file, 0, 0, 0, 127);
    } else {
        $file = false;
        $bgcolor = false;
    }
    if ($file === false) {
        return false;
    }
    $thumbnail = imagecreatetruecolor($width, $height);
    if ($thumbnail === false) {
        return false;
    }
    if (regexp_match('\\.gif$', $original)) {
        imagefill($thumbnail, 0, 0, $bgcolor);
        imagecolortransparent($thumbnail, $bgcolor);
    } elseif (regexp_match('\\.png$', $original)) {
        imagefill($thumbnail, 0, 0, $bgcolor);
        imagealphablending($thumbnail, false);
        imagesavealpha($thumbnail, true);
        imagecolortransparent($thumbnail, $bgcolor);
    }
    $result = imagecopyresampled($thumbnail, $file, 0, 0, 0, 0, $width, $height, $original_width, $original_height);
    if ($result === false) {
        return false;
    }
    if ($output) {
        if (regexp_match('\\.gif$', $original)) {
            $result = imagegif($thumbnail, $output);
        } elseif (regexp_match('\\.(jpeg|jpg|jpe)$', $original)) {
            $result = imagejpeg($thumbnail, $output, $quality);
        } elseif (regexp_match('\\.png$', $original)) {
            $result = imagepng($thumbnail, $output);
        } else {
            $result = false;
        }
    } else {
        header('Content-type: ' . file_mimetype($original));
        if (regexp_match('\\.gif$', $original)) {
            $result = imagegif($thumbnail);
        } elseif (regexp_match('\\.(jpeg|jpg|jpe)$', $original)) {
            $result = imagejpeg($thumbnail, null, $quality);
        } elseif (regexp_match('\\.png$', $original)) {
            $result = imagepng($thumbnail);
        } else {
            $result = false;
        }
    }
    if ($result === false) {
        return false;
    }
    imagedestroy($thumbnail);
    return true;
}
예제 #9
0
function ac_download_file($file, $contentType = null, $rename = null)
{
    if (ob_get_length()) {
        ob_end_clean();
    }
    if (!is_readable($file)) {
        return false;
    } else {
        $contentType = !empty($contentType) ? $contentType : file_mimetype($file);
        header('Content-Description: File Transfer');
        header('Content-Type: ' . $contentType);
        header('Content-Disposition: attachment; filename=' . ($rename ? str_replace(" ", "_", trim($rename, " \n\r\t")) : basename($file)));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
}
예제 #10
0
파일: mail.php 프로젝트: refirio/levis
/**
 * Send encoded mail.
 *
 * @param string $to
 * @param string $subject
 * @param string $message
 * @param array  $headers
 * @param string $parameters
 * @param array  $files
 *
 * @return bool
 */
function mail_send($to, $subject, $message, $headers = array(), $parameters = null, $files = array())
{
    $subject = mb_convert_kana(unify($subject), 'KV', MAIN_INTERNAL_ENCODING);
    $message = mb_convert_kana(unify($message), 'KV', MAIN_INTERNAL_ENCODING);
    $subject = mb_convert_encoding($subject, 'JIS', MAIN_INTERNAL_ENCODING);
    $message = mb_convert_encoding($message, 'JIS', MAIN_INTERNAL_ENCODING);
    $subject = '=?iso-2022-jp?B?' . base64_encode($subject) . '?=';
    if (empty($files)) {
        $boundary = null;
    } else {
        $boundary = rand_string();
    }
    if (empty($files)) {
        $body = $message;
    } else {
        $body = "--{$boundary}\n";
        $body .= "Content-Type: text/plain; charset=\"iso-2022-jp\"\n";
        $body .= "Content-Transfer-Encoding: 7bit\n";
        $body .= "\n";
        $body .= "{$message}\n";
        foreach ($files as $file) {
            if (!is_file($file)) {
                continue;
            }
            $filename = basename($file);
            $body .= "\n";
            $body .= "--{$boundary}\n";
            $body .= "Content-Type: " . file_mimetype($file) . "; name=\"{$filename}\"\n";
            $body .= "Content-Disposition: attachment; filename=\"{$filename}\"\n";
            $body .= "Content-Transfer-Encoding: base64\n";
            $body .= "\n";
            $body .= chunk_split(base64_encode(file_get_contents($file))) . "\n";
        }
        $body .= '--' . $boundary . '--';
    }
    if (!isset($headers['X-Mailer'])) {
        $headers['X-Mailer'] = 'PHP';
    }
    if (!isset($headers['From'])) {
        $headers['From'] = '"From" <*****@*****.**>';
    }
    if (!isset($headers['MIME-Version'])) {
        $headers['MIME-Version'] = '1.0';
    }
    if (!isset($headers['Content-Type'])) {
        if (empty($files)) {
            $headers['Content-Type'] = 'text/plain; charset="iso-2022-jp"';
        } else {
            $headers['Content-Type'] = 'multipart/mixed; boundary="' . $boundary . '"';
        }
    }
    if (!isset($headers['Content-Transfer-Encoding'])) {
        $headers['Content-Transfer-Encoding'] = '7bit';
    }
    $header = null;
    foreach ($headers as $key => $value) {
        if ($header) {
            $header .= "\n";
        }
        $key = regexp_replace('(\\r|\\n)', '', $key);
        $value = regexp_replace('(\\r|\\n)', '', $value);
        $header .= $key . ': ' . $value;
    }
    return mail($to, $subject, $body, $header, $parameters);
}
예제 #11
0
 public function meta($uri = false, $null = false)
 {
     $_ = array();
     $_['size'] = filesize(self::sanitize($this->path . '/' . $uri));
     $_['mime'] = file_mimetype(self::sanitize($this->path . '/' . $uri));
     return $_;
 }
예제 #12
0
function update_attachments($var, $upload_path, $file_name_prefix, $max_count, $old_attachments)
{
    $temp = $old_attachments;
    for ($i = 1; $i <= $max_count; $i++) {
        if (isset($_REQUEST['is_' . $var . '_' . $i])) {
            $old_file_name = '';
            if (isset($temp[$i]['file'])) {
                $old_file_name = $temp[$i]['file'];
            }
            $file_name = update_file($var . '_' . $i, $upload_path, $file_name_prefix . '_' . $i, $old_file_name);
            if (!isset($temp[$i])) {
                $temp[$i] = array('file' => '', 'mime_type' => '', 'text' => '');
            }
            $temp[$i]['file'] = $file_name;
            $temp[$i]['mime_type'] = file_mimetype($file_name);
        } else {
            $old_file_name = '';
            if (isset($temp[$i]['file'])) {
                $old_file_name = $temp[$i]['file'];
            }
            if ($old_file_name != '') {
                delete_file($upload_path, $old_file_name);
            }
            unset($temp[$i]);
        }
        if (isset($_REQUEST[$var . '_' . $i . '_text'])) {
            if (!isset($temp[$i])) {
                $temp[$i] = array('file' => '', 'mime_type' => '', 'text' => '');
            }
            $temp[$i]['text'] = $_REQUEST[$var . '_' . $i . '_text'];
        }
        /*		
        		if($temp[$i]['text'] == '' && isset($_REQUEST['is_'.$var.'_'.$i]) &&
        			isset($_FILES[$var.'_'.$i]) && ($_FILES[$var.'_'.$i]['error'] == UPLOAD_ERR_OK))
        				$temp[$i]['text'] = file_filename($_FILES[$var.'_'.$i]['name']);
        */
    }
    $result = array();
    foreach ($temp as $i => $row) {
        if ($row['file'] || $row['text']) {
            $result[$i] = $row;
        }
    }
    ksort($result);
    return $result;
}
예제 #13
0
 protected function render_file_content(&$renderer)
 {
     $name = $this->file_name;
     $renderer->internalmedia($this->project->id($name));
     if (!isset($attributes['display']) || $attributes['display'] != 'link') {
         $mime = file_mimetype($this->ID, $this->project);
         if (substr($mime, 0, 5) == 'text/' || $mime == 'plain/text') {
             render_code($renderer, file_get_contents($this->project->path() . $name), 'unspecified');
         }
     }
 }
예제 #14
0
파일: Ajax.php 프로젝트: robbiespire/paQui
	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);

		sleep(5);
		$Settings->delete($tmp.'_import_progress');

		exit();
	}