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 7178485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:55:50+00:00 2026-05-28T16:55:50+00:00

Hello I’m doing file upload with Yii. I have implemented this way and it

  • 0

Hello I’m doing file upload with Yii. I have implemented this way and it works very nice:

View:

echo CHtml::form($this->createUrl('uploadreport'), 'post', array('enctype'=>'multipart/form-data'));
<div id="div_upload" class="row" style="display:none">
    <?php
    $this->widget('CMultiFileUpload',array(
        'name'        => 'files',
        'accept'      => 'doc|docx',
        'max'         => 1,
        'htmlOptions' => array('size' => 25),
    ));

    echo CHtml::submitButton('Upload');
    ?>
</div>

Controller:

if (isset($_FILES['files'])) {
    $tmp_name = $_FILES['files']['tmp_name'][0];
    $filename = $_FILES['files']['name'][0];
    $new_url = '/home/ivan/reports/'.$filename;

    // Upload file
    move_uploaded_file($tmp_name, $new_url);

    $calc_id = $_POST['calc_id'];

    // Check if there is a previous report
    $report = Report::model()->findByAttributes(array('calc_id'=>$calc_id));
    if (isset($report)) {
        // If there is a previous report, delete it
        $qtxt = "DELETE FROM `tbl_reports` WHERE `calc_id` LIKE '$calc_id';";
        $exec = Yii::app()->db->createCommand($qtxt)->execute();
    }

    // Insert the new report
    $rep_add = new Report;
    $rep_add->calc_id = $calc_id;
    $rep_add->report_url = $new_url;
    $rep_add->save();
}

As you can see in my view I am using CHtml::submitButton. But I would like to use this instead:

echo CHtml::button(
    'Upload Report', array(
        'ajax'    => array(
            'type' => 'POST',
            'url'  => CController::createUrl('Calculator/uploadReport'),
        )
    )
);

But if I use the above, then in my controller $_FILES['files'] comes empty or if I try CUploadedFile::getInstance(); it returns an empty string.

I want to use ajax because I don’t want to render any other view I want the user to remain in the current view after he/she uploads the file. How can I use Ajax or how can I stop the refreshing of the current view when I use CHtml::submitButton('Upload');

Any hints/help appreciated.

  • 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-05-28T16:55:50+00:00Added an answer on May 28, 2026 at 4:55 pm

    I ended up using EAjaxUpload extension. I think it is not possible to handle file uploads through Ajax in Yii.

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

Sidebar

Related Questions

Hello! I have this trouble: I'm searching reports by date and in html view
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello i'm doing a application in php, and i have a list of items
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello I have a custom control. This custom control has it's DataContext set to
Hello I have a problem using latest vim with omnicompletion while editing a file
Hello I have asp mvc view page, <%@ Page Language=C# Inherits=System.Web.Mvc.ViewPage<System.Drawing.Color[,]> %> how I
Hello everybody i have asp.net mvc4 application where i made countdown something like this:
Hello I have a loop which renders elements within a partial view. The elements

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.