Warning filesize stat failed for

I am trying to get the file size of an image and I keep getting Warning: filesize(): stat failed for img.jpg

This is what I did:

I am able to get the file extension no problem but the filesize() just doesn’t seem to work. I have been reading a bit and did find this but it did not solve the problem. Any help is much appreciated!

3 Answers 3

[‘name’] in the $_FILES array is the name of the file on the CLIENT machine. It is information only, and has absolutely no relevance to what’s actually stored on your server. You need to look at [‘tmp_name’] , which is where PHP has stored the file temporarily on the server, after the upload completed:

$_FILES[‘profile’][‘name’] has just name of the file.. you need to access

will give you the temporary path of the file on your system. Here is http://php.net/manual/en/reserved.variables.files.php

also you can access size of file with

Would result in:

This means that your variable

is NOT pointing to a valid file location on the SERVER and is instead one among:

  1. The file path on the client PC (not on the server) and in that case for sure you have not access to it directly
  2. Something that is not a string
  3. BUT it is not null (otherwise you simple would have returned null (see first example)

Please next time post valid PHP code.

UPDATE

As Marc B suggested you have to use $_FILES[‘profile’][‘tmp_name’];

cache()->remember() has just started throw this error (as of yesterday), seemingly at random. In-fact I cannot replicate at all, but our production server throws it on occasion a few times in a day.

Читайте также:  Kitfort вафельница для детских вафель

I’m beginning to see this crop up as a problem in Laravel 5.8 for devs around the world, but we’re on 5.7 and our version hasn’t changed in a few weeks. 5.7.28 .

Our stack trace is as follows:

When the cache refreshes it deletes da/f0/daf031f370ff42af0f4ee58ca9bb3979a18e0fd8 and re-creates it again. I am wondering if it’s a race condition that Laravel isn’t handling, maybe the default function cache()->remember() is taking too long for one user, and the second user accessing it is causing the filesize() check on the missing cache file? I just don’t see why it’s happening now, but not last week.

We’re literally just running $cache = cache()->remember($key, $this->cacheFor, $default); where $default is the callback. Our callback is to a 3rd party API which could explain random timing differences in the response before the cache is filled.

Please sign in or create an account to participate in this conversation.

Я пытаюсь получить размер файла изображения, и я продолжаю получать Warning: filesize(): stat failed for img.jpg

Это то, что я сделал:

Я могу получить расширение файла без проблем, но filesize() просто не работает. Я немного читал и нашел этот, но это не решило проблему. Любая помощь высоко ценится!

[‘name’] в массиве $_FILES — это имя файла на машине CLIENT. Это только информация и не имеет абсолютно никакого отношения к тому, что на самом деле хранится на вашем сервере. Вам нужно посмотреть [‘tmp_name’] , где PHP временно хранит файл на сервере после завершения загрузки:

$_FILES[‘profile’][‘name’] имеет только имя файла.. вам нужно получить доступ к

предоставит вам временный путь файла в вашей системе. Здесь http://php.net/manual/en/reserved.variables.files.php

Читайте также:  Chip fan fail or speed too low

также вы можете получить доступ к размеру файла с помощью

Это означает, что ваша переменная

НЕ указывает на правильное расположение файла на сервере SERVER и вместо него входит:

  • Путь к файлу на клиентском компьютере (а не на сервере), и в этом случае вы точно не имеете доступа к нему.
  • Что-то, что не является строкой
  • НО это не null (иначе вы бы просто вернули null (см. первый пример)

В следующий раз отправьте действующий PHP-код.

UPDATE

Поскольку Marc B предложил вам использовать $_FILES[‘profile’][‘tmp_name’];

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *