Symfony UploadedFile not loading

I am trying to create an UploadedFile from an existing file. But it does not load successfully, nor does it show any errors.

Here is my code

   $encoded_data = "This is a huge string";
   $filename = "tempFile";
   $handle = fopen($_SERVER['DOCUMENT_ROOT'].$filename, "a+")
   file_put_contents($_SERVER['DOCUMENT_ROOT'].$filename, $encoded_data);
   $file = new UploadedFile($_SERVER['DOCUMENT_ROOT'].$filename, $filename, null, filesize($_SERVER['DOCUMENT_ROOT'].$filename));
   var_dump($file->getClientSize());
   var_dump($file->getError());
   var_dump($file->isValid());
   var_dump(is_uploaded_file($file));

Result

int 21
int 0
boolean false
boolean false

I am sure that tempFile exists in the root directory of the document!

+4
source share
1 answer

is_uploaded_file() , , , . isValid() false, is_file_uploaded() . , UploadedFile $test, , true, isValid() , . , . true, isValid() true . , , , ,

+1

Source: https://habr.com/ru/post/1612064/


All Articles