Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:16:43+00:00 2026-06-13T01:16:43+00:00

I have made a component in joomla in order to upload and save files

  • 0

I have made a component in joomla in order to upload and save files as blob in the database.
The file seems to be getting uploaded normally, but when I try to download it I get an error:

7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)

Error: /tmp/payeddownloadsvisits-17.zip: Can not open file as archive

Errors: 1

This is what I have tried, in the view

<div id="dialog" title="Basic dialog" style="display:none;">    
   <form enctype="multipart/form-data" action="index.php?option=com_virtuemart&view=payeddownloads&task=uploadfile" method="post">
        <table>
            <tr><td>Product</td><td><select id="product" name="product"></td></tr>
            <tr><td>File</td><td><input name="file" type="file" id="file"/></td></tr>
            <tr><td></td><td><input name="upload" type="submit" id="upload" value=" Upload "></td></tr>
            <tr><td></td><td></td></tr>
        </table>
        <input type="hidden" name="MAX_FILE_SIZE" value="2000000">          

    </form>
    <progress style="display:none;" id="progress"></progress>   
</div>

this is the controler function

function uploadfile()
     {      
        $payeddownloadsModel = VmModel::getModel('payeddownloads');
        $payeddownloads = $payeddownloadsModel->uploadfile();

        JRequest::setVar('view', 'payeddownloads');
        JRequest::setVar('layout','default');        
        parent::display();                                      
     }

and this is the model function

public function uploadfile(){       
         $input = new Jinput;
         $virtuemart_product_id = $input->get('product');

         $fileName = $_FILES['file']['name'];
         $tmpName =  $_FILES['file']['tmp_name'];
         $fileSize = $_FILES['file']['size'];
         $fileType = $_FILES['file']['type'];
         $fp = fopen($tmpName, 'r');
         $content = fread($fp, filesize($tmpName));
         $content = addslashes($content);
         fclose($fp);

         if(!get_magic_quotes_gpc())
         {
         $fileName = addslashes($fileName);
         }


         $data =new stdClass();
         $data->id = null;
         $data->virtuemart_product_id = $virtuemart_product_id; 
         $data->file_size = $fileSize;
         $data->file_name = $fileName;
         $data->file_type = $fileType;
         $data->file_blob = $content;
         $data->reg_date = date("Y-m-d H:i:s");

         $db = JFactory::getDBO();
         $db->insertObject( '#__virtuemart_payeddownload_productfiles', $data, 'id' );

    }

The file is inserted in the table with the following structure

CREATE TABLE `ivf27_virtuemart_payeddownload_productfiles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `virtuemart_product_id` varchar(45) DEFAULT NULL,
  `file_blob` blob,
  `file_size` varchar(45) DEFAULT NULL,
  `file_name` varchar(200) DEFAULT NULL,
  `file_type` varchar(45) DEFAULT NULL,
  `reg_date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8$$

But when I try to download it:

public function getfile(){

        $jinput = JFactory::getApplication()->input;        
        $file_id = $jinput->get('file_id','','INT');        

        $sql = "select * from #__virtuemart_payeddownload_productfiles where id=$file_id";
        $db = JFactory::getDBO();       
        $db->setQuery($sql);
        $results = $db->loadObjectList();
        $file_size = $results[0]->file_size;
        $file_type = $results[0]->file_type;
        $file_name = $results[0]->file_name;
        $file_blob = $results[0]->file_blob;


        header('Content-Description: File Transfer');           
        header("Content-Type: $file_type");
        header("Content-Disposition: attachment; filename= $file_name");
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . strlen($file_blob));

        ob_clean();
        flush();

        echo $file_blob;
        exit;
    }

I get the following message from the browser:

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)

Error: /tmp/payeddownloadsvisits-17.zip: Can not open file as archive

Errors: 1

But I made a test.php file outside the joomla framwork and uploaded the file again like this:

<?php         
 include("config.php");

 $fileName = $_FILES['userfile']['name'];
 $tmpName =  $_FILES['userfile']['tmp_name'];
 $fileSize = $_FILES['userfile']['size'];
 $fileType = $_FILES['userfile']['type'];
 $fp = fopen($tmpName, 'r');
 $content = fread($fp, filesize($tmpName));
 $content = addslashes($content);
 fclose($fp);

 if(!get_magic_quotes_gpc())
 {
 $fileName = addslashes($fileName);
 }

 $query = "INSERT INTO ivf27_virtuemart_payeddownload_productfiles set file_name='".$fileName."', file_size='".$fileSize."', file_type='".$fileType."', file_blob='".$content."'";        
 mysql_query($query) ;    
?>     

The file is uploaded successfully as expected + when I go back and download it from joomla I can open it – unzip it and read it normally.

So the problem occurs only when I upload the file from joomla 2.5 framework. I can download the file but I can’t unzip it.
If I upload the file from outside joomla, I can download the file normally and unzip it.

What is causing this and how can I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:16:45+00:00Added an answer on June 13, 2026 at 1:16 am

    You’ve added slashes to the content before saving to the database, but you didn’t strip them after retrieving it. Stop using addslashes for security purposes, use the database functions, and you won’t break your own data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made Joomla component with frontend and backend (admin). Now I need to
I have a component that is made up of various components such as a
I made a component for Joomla and it's working ok with the direct url:
I made a custom component in Joomla 2.5, and I need to reference custom
hi there everyone i have a question on joomla, i have made a site
I made Joomla admin component according to Joomla guide - http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component In that i
I am looking for a Joomla 2.5+ component to edit the language files (ex:
I have made a Custom Component in XML, consisting of a button with an
I am having trouble getting the Auth component redirect. I have a login form
I have a component in joomla that exports to PDF, the problem that i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.