यह एक श्रेष्ठ बनने के रूप में इरादा नहीं है, लेकिन pǝlɐɥʞ के सुझाव एक शुद्ध पीएचपी कार्यान्वयन कि वह सब फिर से प्रयोग करने योग्य नहीं है का उपयोग कर सकते हैं। आप सिंटैक्स $ this-> load-> image ('images/gorilla.png') का उपयोग करना चाहते थे, तो यहां आप यह कैसे कर सकते हैं।
/application/libraries/MY_Loader.php बनाएं
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Loader Class
*
* Loads views and files
*
* @package CodeIgniter
* @subpackage Libraries
* @author Phil Sturgeon
* @category Loader
* @link http://codeigniter.com/user_guide/libraries/loader.html
*/
class MY_Loader extends CI_Loader {
function image($file_path, $mime_type_or_return = 'image/png')
{
$this->helper('file');
$image_content = read_file($file_path);
// Image was not found
if($image_content === FALSE)
{
show_error('Image "'.$file_path.'" could not be found.');
return FALSE;
}
// Return the image or output it?
if($mime_type_or_return === TRUE)
{
return $image_content;
}
header('Content-Length: '.strlen($image_content)); // sends filesize header
header('Content-Type: '.$mime_type_or_return); // send mime-type header
header('Content-Disposition: inline; filename="'.basename($file_path).'";'); // sends filename header
exit($image_content); // reads and outputs the file onto the output buffer
}
कुछ तरीके हैं जिन्हें आप इस का उपयोग कर सकते हैं:
बेसिक उत्पादन (डिफ़ॉल्ट jpeg है)
$this->load->image('/path/to/images/gorilla.png');
अन्य छवि प्रकारों का उपयोग करने के लिए माइम-प्रकार भेजें
$this->load->image('/path/to/images/gorilla.jpg', 'image/jpeg');
वापसी छवि
$image = $this->load->image('/path/to/images/gorilla.php', TRUE);
वैसे ही जैसे $ this-> load-> दृश्य
, 3 पैरामीटर सही पर सेट किया जा रहा मतलब है कि यह सीधे outputting के बजाय वापस आ जाएगी।
आशा इस :-)
स्रोत
2009-12-16 10:30:25
सही काम करता है, धन्यवाद! – Ethan
मैं कोडनिर्देशक के वर्तमान संस्करण पर काम कर रहा हूं। यह कोड मेरे लिए काम नहीं कर रहा है –
मुझे लगता है कि 'निकास' कमांड का कोई उद्देश्य नहीं है, क्योंकि 'मर' स्क्रिप्ट को समाप्त करता है और वे वही काम करते हैं। रास्ते से कोड के लिए धन्यवाद। –