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

Jake N
  • 10,535
  • 11
  • 66
  • 112

8 Answers8

1

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

  • Did that too. It would be a permissions error if that were the case? Rather than _FILES being empty? – Jake N Jul 03 '14 at 08:05
  • 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. – user2361810 Jul 03 '14 at 08:31
  • Thats not it, var is completed 777'd and its the same – Jake N Jul 03 '14 at 13:32
  • Can you add logs and exception files. We can get detailed info from there. – user2361810 Jul 03 '14 at 15:39
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.

Kevin Sandow
  • 4,003
  • 1
  • 20
  • 33
  • A tiny file (7KB) fails also. Image files work fine from within Magento's usual admin area. – Jake N Jul 08 '14 at 16:15
1

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

MTM
  • 919
  • 10
  • 22
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.

ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38
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.

Community
  • 1
  • 1
birdspider
  • 3,034
  • 1
  • 16
  • 25
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.

sensorario
  • 20,262
  • 30
  • 97
  • 159
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;
peterpeterson
  • 1,315
  • 2
  • 14
  • 38
-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.

Community
  • 1
  • 1