I wanna copy some doc files from a link. But, sometimes there's link that we don't have permission to access or the link that expired. For the link that we don't have permission, is there a solution?
and I wanna change the error message when it happen, the error message that I get is :
Warning: copy(http://www-cgi.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ngm/15-721/summaries/12.pdf) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in D:\AppServ\www\academicopter\functionWrapper.php on line 33
I've tried to change the error message with (or die ('CANNOT COPY')) the code below :
copy($Link, $savePath . basename($Link)) or die ('CANNOT COPY');
but, the error message still same warning ..... how to change it? thank you :)
You can muffle the warning using the # operator. Note that it would still run any custom error handler you may have configured.
if (false === #copy(...)) {
// copy failed
}
AFAIK there's no other way to get rid of the warning unless you use cURL to copy the file instead.
Edit
You could also use get_headers($url) and look for HTTP/x.x 403. It's one more request and personally I would save myself the trouble :)
Related
I'm very new here but I'm facing an issue on one of my website with fopen().
$file="//".$_SERVER['SERVER_NAME']."/myfile".date("Ymd").".txt";
if (!file_exists($file)) {
$fp=fopen($file,"w+");
}
$fp=fopen($file,"r+");
And the error message :
fopen(mydomain/myfile20160629.txt): failed to open stream: No such file or
directory in /mydomain/myphpfile.php on line 24
What's funny is that I sometimes get an error message, sometimes not, depending what file use this. And I still got this message when the file is created...
Do you have any idea ?
Try set path : $file="//".$_SERVER['DOCUMENT_ROOT']."/myfile".date("Ymd").".txt";
but before that, move your file in directory $_SERVER['DOCUMENT_ROOT']
Getting this error after I hit this website 20 times IP blocking or any other thing I don't know why.
Warning:
file_get_contents(http://www.azlyrics.com/a.html?time=1454075435):
failed to open stream: HTTP request failed! in
C:\xampp\htdocs\travel\simple_html_dom.php on line 77 Fatal error:
Call to a member function find() on boolean in
C:\xampp\htdocs\travel\searchplaylist.php on line 61
I've Code files
If you want to I'll upload
both file codes in this link
https://drive.google.com/folderview?id=0BzMyD6UnaIfWZDZFWXN3akFwd2s&usp=sharing
Just add # infront of file_get_contents. (#file_get_contents).
This will not raise any errors if the request fails due to any reason.
My issue was that the server i was getting content from might be down sometimes and during those times i got an error. # will not raise them.
But remember to use this only in cases where you understand why it might fail and you just want to handle those cases. Don't use it somewhere where you might have made mistakes and want to hide them.
In Dropbox api, this error occurs:
Warning: file_put_contents(dropbox/tokens/766tYP3FZu8IEv4d.token) [function.file-put-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\dropbox\dropboxupload.php on line 28
Authentication requiredhttps://www.dropbox.com/1/oauth/authorize?oauth_token=766tYP3FZu8IEv4d&oauth_callback=http%3A%2F%2Flocalhost%2Fdropbox%2Fdropboxupload.php%3Fauth_callback%3D1
How can this error be solved?
Errors are returned using standard HTTP error code syntax. Any additional info is included in the body of the return call, JSON-formatted. Error codes not listed here are in the REST API
Create folder at root name "tokens" and try again
warning is due to not having "tokens" folder in your dropbox directory at root level.
create one.
second Oauth doesnot work on a Local Machine .
try to Upload it on a server and try again .
Hello i have a stupid question i search in stackflow there was lots of answeserd but i couldnt find solution for my problem i want to call a file in php receiving error actually the code is correct but i am receiving a problem error which is:
Warning: require_once(1) [function.require-once]: failed to open stream:
No such file or directory in C:\xampp\htdocs\Upload images\upload.php on line 2
Fatal error: require_once() [function.require]: Failed opening required '1'(include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Upload
images\upload.php on line 2
I am using dreamweaver. i deleted the path with directory and recreated with different name but not solved still prob exist. also i did google there also i didn't find solution ??????? any one please my head is exploding....??????????????????????????????
A quick test on my system reveals that require_once("file") or error_function(); fails with that exact message; require_once("file"); does not.
This is possibly because require_once is a statement rather than a function, and might have different parsing rules, causing your statement to actually be require_once('db.php' or mysql_error());. The PHP or operator with those arguments will return TRUE without calling mysql_error, causing the statement to be require_once(1) (1 == TRUE) - which would generate those messages. This is just my speculation.
tl;dr
Try removing the or mysql_error() from your code. require_once will generate a fatal error anyway. (Warning: Works On My Machineā¢.)
Try write complete path in require_once(path)
I am working with the move_uploaded_file() function in PHP. I've managed to successfully troubleshoot a problem I was encountering, but I would like to be able to get the actual content of the warnning or error message. According to php.net (http://php.net/manual/en/function.move-uploaded-file.php) the move_uploaded_file() function returns FALSE and a warning on failure. I want the actual content of the warning, such as "failed to open stream: Permission denied..." so that I can record which errors are occurring. Is there a way to do this?
You can do using this: $_FILES['userfile']['error']
More info: http://php.net/manual/en/features.file-upload.errors.php