Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Errors or Warranings

Posted on 2009-04-16
7
Medium Priority
?
310 Views
Last Modified: 2012-05-06
Is there any way to control how PHP handles errors?

im getting "Warning: ftp_get() [function.ftp-get]: IDX_2/pics-residential-20090415.tar: No such file or directory in /php/databasePopulate.php on line 73
File does not exist"

When i get the warring the script dies.
I need the script to complete even if the the file is not on the server.

Thanks!
0
Comment
Question by:Cybervanes
  • 3
  • 2
  • 2
7 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 24161602
Consider changing the code to use the file_exists http://us2.php.net/file_exists function so you first check if the file exists then if it does call the ftp_get function and if it does not you simply proceed with the remainder of the script without calling ftp_get.

You can use the error_reporting http://us.php.net/manual/en/function.error-reporting.php function to fine tune what you would like PHP to display on the screen but the first approach I mentioned above is the proper technique.
0
 
LVL 8

Expert Comment

by:aldanch
ID: 24161760
That function returns true or false. I have never used it but could you just do something like this?
if(ftp_get(...)) {
     echo "Got it.";
} else {
     echo "Failed.";
}

Open in new window

0
 
LVL 2

Author Comment

by:Cybervanes
ID: 24161986
aldanch:
what you suggested is exactly what I'm using, and it kills the script with out executing the else{} statement.

LordOfPorts:
im still unclear on how to query a different server via ftp using if(file_exists()){}.

any other ideas?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Accepted Solution

by:
aldanch earned 1000 total points
ID: 24162039
What happens when you suppress the error using this?


@ftp_get(...)

Open in new window

0
 
LVL 2

Author Comment

by:Cybervanes
ID: 24162147
aldanch:
worked perfectly!!

what dose the @ symbol do or what dose it stand for?

I'm still a bit green with php
0
 
LVL 8

Expert Comment

by:aldanch
ID: 24162220
The @ symbol is an error/warning suppressor :)

Glad I could help!
0
 
LVL 19

Assisted Solution

by:LordOfPorts
LordOfPorts earned 1000 total points
ID: 24162433
You can also suppress warnings through the error_reporting http://us.php.net/manual/en/function.error-reporting.php function, e.g. at the top of your page place:

// This way no warnings would be shows, this could be used for production
error_reporting(E_ERROR | E_PARSE);

// - OR

// Disable all errors/warnings/etc.
error_reporting(0);

// In development you do want to see all issues
error_reporting(E_ALL);

If you add @ in front of functions it does silence the warnings but presents an issue when you develop as you might not see problems beforehand.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question