I am using Moodle 2.2 and using TCPDF to generate certificates for students. When user completes the course, Teacher should get the student's certificate as an email attachment.
For normal viewing of certificate I don't have any issue, but when comes to attachment I have to save it on server first. For that I have to invoke 'file_get_contents' method.
But I am getting error.
Code:
file_put_contents($CFG->dataroot.'/certificate/'.$USER->firstname.'_certificate.pdf', file_get_contents($certurl))
Error:
Warning:
file_get_contents(https://example.com/moodle/mod/certificate/view.php?id=84&action=get&uid=19):
failed to open stream: Connection timed out in
/usr/local/apache/htdocs/moodle/mod/quiz/view.php on line 290
It seems file_get_contents returns blank string. I tried cURL also. Both the options work fine to generate and view PDF online. But fails while saving it on server.
Note: I am facing this issue in my new server. It was working fine on my old server.
Related
I have Worked out what is causing the issue but I don't know what I need to do to fix it.
I updated the parent router and my code stopped working.
figured it was just a new IP issue so fixed that but still wouldn't work. ran the code manually and got the issue
Warning: file_get_contents failed to open stream: Connection timed out error
This code creates a web address that when sent updates my solar recordings.
I remote into the PI from my house and can paste the link in the browser and it works fine but something stopping it on the device itself.
I narrowed it down to the new router somehow blocking my script from sending a link.
I chucked the device into DMZ on the router and it works fine...
guessing I need to open some ports or allow something but don't know what. I don't want to keep the device in DMZ
I can not find any answer to this as most problems revolve around a file not existing or a delete process not working.
I have an FTP device where I generate a file with an PHP script. After that, I try to FTP in, get the file and after that, delete it.
This all works fine, I can connect, get the file and save it locally and then delete it. Except for one thing, the ftp_delete() function results in a warning.
PHP gives me the following, when executing the script:
A PHP Error was encountered
Severity: Warning
Message: ftp_delete(): Command okay
I looked up the error code, it means it was successful. And it was because the file is deleted on the FTP device.
So why does this generate an PHP error?
Cheers.
The RFC 959 (FTP specification) mandates that on a successful completion of the DELE command, the server should respond with 250 status code.
The PHP FTP implementation is very strict, yielding a warning on any other code, even if it indicates a success (2xx class).
Your server probably uses some other 2xx code, like a generic 200 Command okay.
I've got a fairly simple cron job that pulls down some files from an FTP server - none of the files are particularly large, but I'm constantly getting the following:
Connected to voip.colefabrics.com, for user colefabrics\absolute
Warning: ftp_get(): Opening BINARY mode data connection. in /home/www/colefabrics.com/httpdocs/libs/classes/class.ftpObj.php on line 56
There was a problem while downloading website/items.csv
Attempt 2:
Connected to voip.colefabrics.com, for user colefabrics\absolute
Warning: ftp_get(): Opening BINARY mode data connection. in /home/www/colefabrics.com/httpdocs/libs/classes/class.ftpObj.php on line 56
There was a problem while downloading website/items.csv
...snip...
I've been through all the other posts relating to this, tried to enforce passive mode, increased the timeout, but nothing is working.
Does anyone know what might be causing this, and what I can do to try and resolve it?
To confirm, it's working fine via a 'normal' FTP client, it's only via PHP that I have a problem.
so I'm trying implement a website which uses data stored in an xml file.
It works fine on my computer, but as soon as I try to upload it, I get the following error:
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "..\lib\menu.xml" in /home/ogwareco/public_html/menu.php on line 2
And none of the data gets displayed on the screen. I've Googled this problem, but it's led nowhere. I've got no idea what to do here. I've even tried to set my permissions to 777 (bad idea, I know), to see if it was a permissions thing, but it's not.
It looks like you are using backslashes to refer to the file on a Linux machine. Change
..\lib\menu.xml
to
../lib/menu.xml
in your code.
I am working on a script that fetches csv files from a web server. I am using file_get_contents presently. Sometimes i get the message
Warning: file_get_contents failed to open stream: Connection timed out
I assume it can be due to website being down. Or can there be a situation where the website is fine but still this warning shows up. Also what advantage does CURL provide over this function.
this is because the remote url is having 404 error.
For accessing remote files, you should use cURL. You can set cURL to timeout quietly if the remote server takes too long.