Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if file exists in php

if (!(file_exists(http://mysite.com/images/thumbnail_1286954822.jpg))) {    $filefound = '0';                          } 

why won't this work?

like image 591
anonymous Avatar asked Nov 23 '10 06:11

anonymous


People also ask

How do you check if a file already exists in PHP?

The file_exists() function checks whether a file or directory exists.

How do I check to see if a file exists?

To check if a file exists, you pass the file path to the exists() function from the os. path standard library. If the file exists, the exists() function returns True . Otherwise, it returns False .

How do you check if a file is uploaded PHP?

The is_uploaded_file() function in PHP is an inbuilt function which is used to check whether the specified file uploaded via HTTP POST or not. The name of the file is sent as a parameter to the is_uploaded_file() function and it returns True if the file is uploaded via HTTP POST.

How create file if not exist in PHP?

PHP Create File - fopen() The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created using the same function used to open files. If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).


2 Answers

if (!file_exists('http://example.com/images/thumbnail_1286954822.jpg')) {    $filefound = '0'; } 
like image 78
Haim Evgi Avatar answered Sep 21 '22 05:09

Haim Evgi


  1. The function expects a string.

  2. file_exists() does not work properly with HTTP URLs.

like image 43
Ignacio Vazquez-Abrams Avatar answered Sep 23 '22 05:09

Ignacio Vazquez-Abrams