473,414 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to check remote file...

Hi,
i want to check whether a file from remote server is existed or
not.

The file_exists() checks for local server only. But i want a function
that checks the remote server.
If anyone knows please help..

thanks in advance...

regards
sree

Aug 17 '06 #1
6 1751
Rik
sree wrote:
Hi,
i want to check whether a file from remote server is existed or
not.

The file_exists() checks for local server only.
Actually, starting at PHP5 it will work on some url's.
But i want a function
that checks the remote server.

If anyone knows please help..

thanks in advance...
I'm not sure exactly how. You could possibly use fsockopen en send a HTTP HEAD
request, and check the response. There may be better options in curl available.

Grtz,
--
Rik Wasmus
Aug 17 '06 #2

Hi Rik,

Do you know the exact options curl???


Rik wrote:
sree wrote:
Hi,
i want to check whether a file from remote server is existed or
not.

The file_exists() checks for local server only.

Actually, starting at PHP5 it will work on some url's.
But i want a function
that checks the remote server.

If anyone knows please help..

thanks in advance...

I'm not sure exactly how. You could possibly use fsockopen en send a HTTP HEAD
request, and check the response. There may be better options in curl available.

Grtz,
--
Rik Wasmus
Aug 17 '06 #3
sree wrote:
Hi,
i want to check whether a file from remote server is existed or
not.

The file_exists() checks for local server only. But i want a function
that checks the remote server.
If anyone knows please help..

thanks in advance...

regards
sree
This will do the trick:

if(@fopen($url, "rb")) {
}

Aug 17 '06 #4
Hi,

No probs. I got the solution for this.

that is,

<?php
$TheImage = "http://www.uk-present.co.uk/images/logo.gif";
if (@fclose(@fopen("$TheImage", "r"))) {
$TheImage = "$TheImage";
}
else {
$TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
}
?>

The first if loop tells you that the image exist, else it does not
exist

However it works only when the server gives you 404 error

Chung Leong wrote:
sree wrote:
Hi,
i want to check whether a file from remote server is existed or
not.

The file_exists() checks for local server only. But i want a function
that checks the remote server.
If anyone knows please help..

thanks in advance...

regards
sree

This will do the trick:

if(@fopen($url, "rb")) {
}
Aug 18 '06 #5
sree wrote:
Hi,

No probs. I got the solution for this.

that is,

<?php
$TheImage = "http://www.uk-present.co.uk/images/logo.gif";
if (@fclose(@fopen("$TheImage", "r"))) {
$TheImage = "$TheImage";
}
else {
$TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
}
?>

The first if loop tells you that the image exist, else it does not
exist

However it works only when the server gives you 404 error

Chung Leong wrote:
>>sree wrote:
>>>Hi,
i want to check whether a file from remote server is existed or
not.

The file_exists() checks for local server only. But i want a function
that checks the remote server.
If anyone knows please help..

thanks in advance...

regards
sree

This will do the trick:

if(@fopen($url, "rb")) {
}

You shouldn't call fclose() on a file handle which never opened. It's
an error - which you're hiding with the @. But the error still occurs,
is still logged and still takes system resources to handle. Better would be:

<?php
$TheImage = "http://www.uk-present.co.uk/images/logo.gif";
if (($fh = fopen("$TheImage", "r"))) {
$TheImage = "$TheImage";
fclose($fh);
}
else {
$TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
}
?>

Generally, if you have to use '@' you should look at why you need to use it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 18 '06 #6
sree wrote:
>
However it works only when the server gives you 404 error
Call stream_get_meta_data() on the file handle returned and parse the
wrapper_data array. That contains the HTTP response header, with the
status code in first element.

Aug 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mark4asp | last post by:
Hello, Is there a simple way to check whether a database driver is available on a remote server? I only have ftp access so I can only run ASP scripts. An ASP application on a host has...
4
by: Dr. StrangeDub | last post by:
I am part of a group that has developed an ASP.Net web application. I am looking for a way to determine whether or not the browser is actually running on the web server. For this case (when...
3
by: Chin Chien Ping | last post by:
Hi, I looking for a solution for how to check if a connection to a remote computer exist or not using vb.net. I 'm writing a program which will request data from a remote sql server. I need...
0
by: Jawahar | last post by:
All I had posted this in the remote assistance group and could not get any replies so I thought that I could try in the developer group Thanks One of the issues we face when helping our remote...
2
by: Jeff | last post by:
I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in the eNPTest02 directory of my localhost on my development machine. The database is on the web. ...
1
by: lauralucas | last post by:
Hello I'm using ASP.NET 1.1, Visual Studio 2003, IIS 5.1 and windows XP as development machine. I can work in this machine locally and create web apps that I can access via localhost. No problem...
3
by: walterbyrd | last post by:
I am working on a timecard app. When somebody logs in, it stamps his/her time. Problem is, I have to make sure that somebody is not logging in from a remote site. I want all the logins from one...
2
by: rn5a | last post by:
A ASP.NET page checks for the existence of a cookie in the Page_Load sub: Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim strUserName As String Dim ckUserName As HttpCookie Dim...
5
by: idorjee | last post by:
hi guys, I'm trying to figure how to read a file from my other computer, and here is what i did. it doesn't work for some reason. i would really appreciate if you could help me with this. i get...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.