We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

$this->request->hasFiles(); is return false! (file upload) on XAMPP

Hi, all!

Sorry about rudimentary question.

[environment]

  • phalcon3.0.3
  • xampp v3.2.2

[[ PHP INFO ]]

  • PHP Version 7.0.13
  • sys_temp_dir : no value
  • upload_max_filesize : 2M
  • upload_tmp_dir : C:\xampp\tmp
  • user_dir : no value

[[QUESTION]]---------------------------

I am trying about image-file upload. But, $this->request->hasFiles(); This value return false;

MY purpose is make thumbnails. Which directory does phalcon refer to?


Source codes

[[HTML]]

<form action="/invo/products/confirm" method="post" enctype="multipart/form-data">
<input type="file" name="up_image" />
<input type=submit>
</form>

[[Controller]]


<?php

use Phalcon\Mvc\Controller;
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\Model as Paginator;

/**
 * ProductsController
 *
 * Manage CRUD operations for products
 */
class ProductsController extends ControllerBase
{
      public function initialize()
      {
        $this->tag->setTitle('Manage your products');
        parent::initialize();
    }

    public function confirmAction()
    {
        // Check if the user has uploaded files
        if ($this->request->hasFiles() == true) {
            // Print the real file names and their sizes
            foreach ($this->request->getUploadedFiles() as $file) {
                echo $file->getName(), " ", $file->getSize(), "\n";
            }
        }else{
            echo "No upload file"; //<========== CAME HERE!!
        }
    }

[[SecurityPlugin.php]]

            //Public area resources
            $publicResources = array(
                'products'      => array('index', 'search', 'new', 'edit', 'save', 'confirm', 'create', 'delete'),

I confirmed this folder(C:\xampp\tmp). There are upload files in this folder!! But $this->request->hasFiles() is not move. Other posted input-values was received.

Please help!!




3.4k

What happens if you do the following;

public function confirmAction()
{
   print_r($_FILES);
   die;
   //...
}


3.6k
edited Feb '17

Thank you "H" !! print_r($_FILES); is printed this.

array(0) {

} Array ( )



3.4k
edited Feb '17

Cool, so we can conclude it's an issue with your request and not with Phalcon.

  • Can you reply with a dump of your request headers and body (omit any sensitive information if you need)
  • What browser are you using? Is it RFC-1867 compliant?
  • Can you reply with the output of php -i | grep file_uploads or echo ini_get("file_uploads");

Thank you "H" !! print_r($_FILES); is printed this.

array(0) {

} Array ( )

edited Feb '17

Your XAMPP has a setup in a wrong manner. I'd guess that your web server does not pass request to the PHP backend.

this is working sample for nginx:

// plain FrontPageController pattern
try_files $uri $uri/ /index.php;

// this is required if we want SUPERGRLOBALS _GET, _REQUEST etc.
try_files $uri $uri/ /index.php$is_args$query_string;


3.6k
edited Feb '17

Hi,"H"!

Sorry about my reply wes late.

I was able to find the factor. By trying what you pointed out,

Thank you so much "H"!

This erroer's reason is Jquery-mobile. I should have added these following lines in JS.

$.mobile.ajaxEnabled = false;

by https://forum.jquery.com/topic/jquery-mobile-seems-to-clobber-ability-to-upload-files-via-forms



3.6k

Thank you ! Mr.Jonathan Aaron Steel.

Your point is verry important to me. Because Now, I can not given the value of PATH_INFO to phalcon on XAMPP and AWS ec2, So,It is substituting other variables.

I will try this question more. If I can not solve it I will post that question at another thread. At that time, I'm so happy if you reply again.

Thanks!