Php - Check File Exists On Url When Server Is Not Giving Error 404

  1. Home
  2. php - check file exists on url when server is not giving error 404
902 votes 2 answers php - check file exists on url when server is not giving error 404 Get the solution ↓↓↓

My question is simple. I want to check if file exist on url or not in PHP.

Something likefile_exist($url).

I googled and found lot of solutions, But none of them is working for me. I think the reason is that My server automatically redirect on error 404.

File is hosted on 000webhost server, And I am checking from my local server. I checked .htaccess file but didn't found any setting in it.

Please guide me if it is possible to code in php or any setting in 000webhost.

Undefined asked 2022-05-4 Write your answer 156 votes

Answer

Solution:

Hello I found below code from net and worked for me..

function is_url_exist($url){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if($code == 200){ $status = true; }else{ $status = false; } curl_close($ch); return $status; } Copy code Write your answer 645 votes

Answer

Solution:

You can use an Exception Handler usingset_error_handler('exceptionHandler function');

Here is what is use

if (!function_exists('exceptionHandler')) { function exceptionHandler($severity, $message, $file, $line) { if ($severity == E_STRICT) { return; } // code logic to handle or display exceptions } } Copy code

This would be the way you can have control over handling exceptions and handle 404 exception here

Write your answer

Share solution ↓

Additional Information:

Date the issue was resolved: 2022-05-4 Link To Source Link To Answer People are also looking for solutions of the problem: invalid argument supplied for foreach() laravel

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

536 Form action is not using the PHP file? 601 How to check whether $_GET['id'] is set and it's not empty using php 920 Laravel php artisan shows error of JWT 778 php - Is it possible to "pirate" a session variable (I do not want to know how) 179 php - Delete files/uploads when delete User 910 php - JSON parser error java.lang.String cannot be converted to JSONObject] Array 824 php - Magento import - Skip row sku is not defined 708 apache - PHP - how to do GET request when username password is asked in a popup? 956 php - Check if a variable has been set with the name of the value of another variable 434 installation - How to install PHP in IIS 7.5, Windows Server 2008 R2 (64bits)

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.https://www.php.net/

Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.

Latest questions:

984 php - Use mysql_fetch_array() with foreach() instead of while()

861 url - PHP Mod_Rewrite

77 javascript - PHP-SDK for Facebook Connect Generating Error on Logout

606 jquery - execute php/javascript function after a certain amount of time has passed

697 php - Extending CI with own library

674 Comparing mysql dates in php

317 php - One HTTPS ajax call in codeigniter

163 php - iPhone SDK - convert strings to call variable names

653 xml - Translate PHP PUT HTTP request to ColdFusion

563 Get php results with jquery ajax

Users questions:

NEW

mysql

NEW

Warning: Undefined array key "program" in E:\xampp\htdocs\pi\alumni.php on line 27 Warning: Undefined array key "enter_course" in E:\xampp\htdocs\pi\alumni.php on line 31 Warning: Undefined array key "enter_address" in E:\xampp\htdocs\pi\alumni.php on line 32

NEW

Rename existing images with keyword in WordPress PHP

NEW

codeigniter

NEW

Class "web_profiler.controller.profiler" does not exist after upgrading symfony 3.4 to 4.4 version

PHP x 410847Laravel x 36785Yii x 3846CodeIgniter x 9997Symfony x 7793CakePHP x 3085Zend Framework x 1235Phalcon x 300FuelPHP x 47Slim x 570JavaScript x 36883React x 550Angular x 1121Vue.js x 181JQuery x 11108Backbone.js x 21Node.js x 463Ember.js x 10Meteor x 7Polymer x 20Aurelia x 1MySQL x 39074CSS x 2497Bootstrap x 1603Foundation x 84UIkit x 4Semantic UI x 2Bulma x 2Animate.css x 1HTML x 20978

This site uses cookies. We use them to improve the performance of our website and your interaction with it. Confirm your consent by clicking OK

OK

Từ khóa » Check 404 Php