Home > Joomla 1.5 > Upload file

Upload file


Add this code in   view/tmpl/
<form name=”upload” method=”post” enctype=”multipart/form-data”>
<input type=”file” name=”file_upload” />
<input type=”submit” name=”submit” value=”submit”/>
<input type=”text” name=”option” id=”option” value=”com_fileuplaod”/>
<input type=”text” name=”view” id=”view” value=”fileuplaod”/>
<input type=”text” name=”task” id=”task” value=”uploadFile”/>
</form>

Add this function in controller:

function uploadFile(){
$file = JRequest::getVar(‘file_upload’, null, ‘files’, ‘array’);
jimport(‘joomla.filesystem.file’);
$filename = JFile::makeSafe($file[‘name’]);
$src = $file[‘tmp_name’];
$dest = JPATH_COMPONENT . DS . “uploads” . DS . $filename;
if ( strtolower(JFile::getExt($filename) ) != ‘jpg’) {
if ( JFile::upload($src, $dest) ) {
//Redirect to a page of your choice
parent::display();
} else {
//Redirect and throw an error message
}
} else {
//Redirect and notify user file is not right extension
}
}

function uploadFile(){
$file = JRequest::getVar(‘file_upload’, null, ‘files’, ‘array’);
jimport(‘joomla.filesystem.file’);
$filename = JFile::makeSafe($file[‘name’]);
$src = $file[‘tmp_name’];
$dest = JPATH_COMPONENT . DS . “uploads” . DS . $filename;
if ( strtolower(JFile::getExt($filename) ) != ‘jpg’) {
if ( JFile::upload($src, $dest) ) {
//Redirect to a page of your choice
parent::display();
} else {
//Redirect and throw an error message
}
} else {
//Redirect and notify user file is not right extension
}
}
Advertisements
Categories: Joomla 1.5
  1. Aneeq
    May 22, 2012 at 8:23 am

    The code to upload file in PHP is very simple, but we need to understand the flow which is a below.

    1. Browse the file from a local system
    2. Upload to server
    3. Server keeps it on a temporary path
    5. Copy from temporary to permanent path

    Create a file upload form

    Filename:

    Note:

    * An enctype attribute of the tag has been specified.
    * This attribute specifies which content-type to use when submitting the form
    * We have used “multipart/form-data” to upload binary data, like the contents of a file, to be uploaded
    * If proper enctype is not provided, upload will not work.
    * File upload is a huge security risk so you must check what type of files are being uploade

    Create a file upload script (upload-file.php)

    This will upload the file to the specified path.

    Note:

    * The default file upload size using a browser is usually 2MB so files larger than this size may not upload. You will have to alter the file upload setting on the server.
    * You need to set write permission to the folder where file needs to be upload.
    * In our case, the “uploads” folder needs to have a 777 permission on a linux/unix server.

    Source:

    http://phphelp.co/2012/05/18/how-to-upload-a-file-in-php/

    OR

    http://addr.pk/a478

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: