2

I am trying to install a Magento package, but I get No file was uploaded

Its coming from this code because $_FILES is an empty array in /downloader/Maged/Controller.php

/**
 * Install uploaded package
 */
public function connectInstallPackageUploadAction()
{
    if (!$_FILES) {
        echo "No file was uploaded";
        return;
    }

    if(empty($_FILES['file'])) {
        echo "No file was uploaded";
        return;
    }

    $info =& $_FILES['file'];

    if(0 !== intval($info['error'])) {
        echo "File upload problem";
        return;
    }

    $target = $this->_mageDir . DS . "var/" . uniqid() . $info['name'];
    $res = move_uploaded_file($info['tmp_name'], $target);
    if(false === $res) {
        echo "Error moving uploaded file";
        return;
    }

    $this->model('connect', true)->installUploadedPackage($target);
    @unlink($target);
}

It might be worth noting that product uploads work fine.

The only log output I get is

2014-07-03T18:44:15+00:00 ERR (3): Warning: array_key_exists() expects parameter 2 to be array, null given in /var/www/vhosts/example.com/httpdocs/app/code/core/Mage/Captcha/Model/Observer.php on line 166

exception.log was empty

3
  • Make sure you are using enctype="multipart/form-data" on your form. Commented Jul 2, 2014 at 16:55
  • The form is within the Magento Connect page, so I would hope it does! A quick look shows it does. Commented Jul 2, 2014 at 17:00
  • apache log? php log? floder permissions? Commented Jul 14, 2014 at 20:33

8 Answers 8

1

Make sure that your var folder in magento installation is fully writable. 777 permission. All folders and files.

Sign up to request clarification or add additional context in comments.

4 Comments

Did that too. It would be a permissions error if that were the case? Rather than _FILES being empty?
Yes, when uploading is done in magento they are initially uploaded to one of the var folders and then used. If files have not been uploaded hence $_FILES empty. Check your log and system exception files it may be other issues as well.
Thats not it, var is completed 777'd and its the same
Can you add logs and exception files. We can get detailed info from there.
1

You can try uploading a small dummy file first to check if the error stays the same.

There is a file upload limit which might be reached.

File upload often fails due to upload_max_filesize or post_max_size being too small as mentioned in Common Pitfalls section of the PHP documentation.

1 Comment

A tiny file (7KB) fails also. Image files work fine from within Magento's usual admin area.
1

Use firebug in firefox to check if your form does has enctype="multipart/form-data".

4 Comments

It does. See comments on the original question.
Is the action of your form directs to connectInstallPackageUpload?
Yes, here is the full form element <form action="/downloader/index.php?A=connectInstallPackageUpload" method="post" target="connect_iframe" onsubmit="onSubmit(this)" enctype="multipart/form-data">
try to print values in indexAction(), use condition like if(isset($_FILES)){print_r($_FILES);exit;} at the start of the indexAction()
1

Check the user group it was created with,

To explain, recently I had some file saving issues. Turned out I had created the folder using the Root user for the server, and the CPanel user ( the one php was running under ) didn't have permission to write in folders owned by the Root account, even when setting the permissions to 777.

Just a thought.

Comments

1

First check if your installation is configured properly see@http://php.net/manual/en/features.file-upload.common-pitfalls.php

Also, if you upload with PUT/xhr the file is on the input stream

$in = fopen('php://input','r');

see@http://php.net/manual/en/features.file-upload.put-method.php and https://stackoverflow.com/a/11771857/2645347,

this would explain the empty $FILES array, in case all else is ok and the upload works via xhr/PUT.

Comments

1

$_FILES is an associative array of items uploaded to the current script via the HTTP POST method. All uploaded files are stored in $HTTP_POST_FILES contains the same initial information, but is not a superglobal. So, ... be sure that method is POST

Always check that your form contains correct enctype:

<form ... enctype="multipart/form-data"> ... </form>

Sometimes happens that when someone upload multiples file, $_FILES return empty. This could happen when I select files that exceed some size. The problem can be in the POST_MAX_SIZE configuration.

1 Comment

This isn't it, please read other comments and answers before posting
1

On

app/code/core/mage/captcha/model/observer.php

change

public function checkUserLoginBackend($observer)
{
$formId = 'backend_login';
        $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
        $loginParams = Mage::app()->getRequest()->getPost('login');
        $login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null;
        if ($captchaModel->isRequired($login)) {
            if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
                $captchaModel->logAttempt($login);
                Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
            }
        }
        $captchaModel->logAttempt($login);
        return $this;
    }

to

public function checkUserLoginBackend($observer)
{
    $formId = 'backend_login';
    $captchaModel = Mage::helper('captcha')->getCaptcha($formId);

    $login = Mage::app()->getRequest()->getPost('username');
    if ($captchaModel->isRequired($login)) {
        if (!$captchaModel->isCorrect($this->_getCaptchaString(Mage::app()->getRequest(), $formId))) {
            $captchaModel->logAttempt($login);
            Mage::throwException(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
        }


    }
    $captchaModel->logAttempt($login);
    return $this;
}

Your issue is: "Captcha Observer throws an error if login in RSS feed" issue #208

or if you wish you could only replace the variable $login to be like this:

$login = array_key_exists('username', array($loginParams)) ? $loginParams['username'] : null;

11 Comments

Thats a good shout, but its not worked. If I put a die statement in that function it does die. So it is running your code, its just not fixed it.
and what happen if you put print_r($_FILES); die(); ?
I get a blank array. I have now upgraded to Magento 1.9 and get the same issue.
That's weird, what kind of error_reporting do you have activated? if not already can you change to E_ALL and run your code again, so if there is a notice of an empty variable, we may have more chances to debug.
Where is best to add this within Magento. I know how to do it, but just unsure when it comes to Magento?
|
-1

You may try out below points. Use Magento Varien File Uploaded Classes to Upload the files.

Magento File Uploader

1) Check enctype="multipart/form-data" in your form.

2) Use Magento Form Key in your form.

3) Use Varien file uploader to upload your files using below links answers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.