2012-06-03 12 views
6

मैं इसे थोड़ी देर के लिए खोज रहा हूं लेकिन मेरी ज़रूरत से मेल खाने का समाधान नहीं मिला। मैं जूमला 2.5 के लिए एक मॉड्यूल विकसित कर रहा हूं। मुझे मॉड्यूल कॉन्फ़िगरेशन में बैकएंड से छवियों/किसी फ़ाइल प्रकार को अपलोड करने की अनुमति देने के लिए कार्यक्षमता की आवश्यकता है।फ़ाइल अपलोड करें जूमला मॉड्यूल

प्रश्न: मैं जूमला मॉड्यूल में फ़ाइल अपलोड के लिए फ़ील्ड कैसे जोड़ सकता हूं।

धन्यवाद!

+0

प्रश्न क्या है? – jzeus

उत्तर

7

बस जूमला डॉक्स से एक नमूना:

<?php 

//Retrieve file details from uploaded file, sent from upload form 
$file = JRequest::getVar('file_upload', null, 'files', 'array'); 

//Import filesystem libraries. Perhaps not necessary, but does not hurt 
jimport('joomla.filesystem.file'); 

//Clean up filename to get rid of strange characters like spaces etc 
$filename = JFile::makeSafe($file['name']); 

//Set up the source and destination of the file 
$src = $file['tmp_name']; 
$dest = JPATH_COMPONENT . DS . "uploads" . DS . $filename; 

//First check if the file has the right extension, we need jpg only 
if (strtolower(JFile::getExt($filename)) == 'jpg') { 
    if (JFile::upload($src, $dest)) { 
     header("Location: http://".$_SERVER["HTTP_HOST"]."/administrator"); Redirect to a page of your choice 
    } else { 
    echo "error !"; //Redirect and throw an error message 
    } 
} else { 
    echo "Wrong extension !"; //Redirect and notify user file is not right extension 
} 

?> 

(रों) अधिक विस्तृत जानकारी और पूर्ण उदाहरण के लिए: http://docs.joomla.org/How_to_use_the_filesystem_package

6

ध्यान रखें कि अपने HTML फ़ॉर्म में शामिल करना चाहिए

enctype="multipart/form-data"

अन्यथा आपको जूमला फ़ंक्शन के साथ कोई परिणाम नहीं मिलेगा!

संबंधित मुद्दे