PHP 8.6.0 Beta 2 available for testing

Yaf_Request_Abstract::getFiles

(Yaf >=3.2.2)

Yaf_Request_Abstract::getFilesFetch uploaded files

Açıklama

public function Yaf_Request_Abstract::getFiles(string $name = ?, mixed $default = ?): mixed

Retrieves a variable from $_FILES.

Bağımsız Değişkenler

name

The variable name. If omitted, the whole array is returned.

default

The value to return if the variable is not found.

Dönen Değerler

The uploaded files array, or default if it is not set.

Örnekler

Örnek 1 Yaf_Request_Abstract::getFiles() example

<?php
class UploadController extends Yaf_Controller_Abstract
{
    public function saveAction()
    {
        $file = $this->getRequest()->getFiles("avatar");

        if (is_array($file) && $file["error"] === UPLOAD_ERR_OK) {
            move_uploaded_file(
                $file["tmp_name"],
                "/var/www/uploads/" . basename($file["name"])
            );
        }
    }
}
?>

Örnek 2 Yaf_Request_Abstract::getFiles() example

<?php
class UploadController extends Yaf_Controller_Abstract
{
    public function saveAction()
    {
        // Assuming a file was uploaded with the form field name "avatar"
        var_dump($this->getRequest()->getFiles("avatar"));
    }
}
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

array(5) {
  ["name"]=>
  string(9) "photo.jpg"
  ["type"]=>
  string(10) "image/jpeg"
  ["tmp_name"]=>
  string(14) "/tmp/phpXvBXqZ"
  ["error"]=>
  int(0)
  ["size"]=>
  int(12455)
}

Ayrıca Bakınız

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top