I've searched as hard as I can, and have been stuck on what seems like such a simple issue.
I'm trying to use fopen() in php to create a simple txt file. My code is as follows:
$myfile = fopen("text.txt", "w") or die("Not Working");
But No matter what I've tried it won't work.
I use Godaddy hosting; plesk on windows.
allow_url_open is on.
and open_basedir is set to none.
I've confirmed this with phpinfo().
I read somewhere that perror can be used, I've tried using it in this context and it doesn't output anything:
$myfile = fopen("text.txt", "w") or perror("error");
I have display_errors set to on.
I'm really racking my brain on what else to try. GoDaddy support was useless.
Any advise on troubleshooting or what else my problem could be based off this information would be very helpful.
Thanks!
Related
I'm having the issue with fopen() on google app engine. Works normal 3-4 times and than this response from server.
Message: fopen(https://website_url/image_name.png): failed to open
stream: Connection closed.
Any idea how to troubleshoot what happened and why?
$image = "https://website_url/image_name.png";
$f = fopen($image,'rb');
php ini has allow_url_fopen = On
First make sure you have the correct path.
You need to give fopen the full path of the file, and you don't need chdir() at all. Try this version:
$path_to_file='url';
$fh = fopen($path_to_file.$filename, 'w') or die('Permission error');
My PHP upload file code is generating an error, randomly, after I changed NOTHING about the code. I did edit the PHP.ini file... but then I changed it back and now my file upload system is broken for no reason. I've simplified the error generated to this example:
$count =0;
foreach ($_FILES['file']['name'] as $filename){
echo ($_FILES["file"]["error"][$count]);
$count+=1;
}
is producing "1" as an error for a valid file. If I knew what "1" meant, I think I'd be able to fix the issue. How can I determine what the error is? As I mentioned, I have changed absolutely nothing about the code, which was working a minute ago and is now not working.
Alright, I should have mentioned this but for people in the future freaking out about multiple file uploads, I'll mention it now. I am using GoDaddy and shared hosting accounts dont have access to some of the filepaths/commands people would normally use with SSH, so SSH is worthless. In GoDaddy though, in CPanel, under Software, there's an option to kill processes. I did this and my PHP script worked with edited PHP.ini. Thanks to everyone for leading me in the right direction – user2954658
Ok, so I have looked everywhere for an answer to this question and can not find it. So I have a php file on my godaddy website. The second I add this line of code to it:
$myfile = fopen("fileName.txt", "r") or die("Unable to open file!");
It prints out this error.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
I have looked through the server error log and found nothing. I have changed the error settings to E_ALL and looked through the logs again and found nothing. I am using Windows plesk hosting on godaddy, and I have changed the checked the boxes for file permissions for write/read/and modify. Nothing seems to work.
Thank you so much for your time, please help!
The problem isn't in the server configuration.
You must change the configuration on the php.ini file. Look fot the allow_url_fopen setting.
I am using php JavaBridge library,
the thing is, I need to include the php client library directly from server using
require_once "someremoteurl.com"
For this allow_url_include should be enabled, but I am in situation where this should be avoided.
Is there anyone who did this before? Is there any workaround?
I tried downloading file real-time using fread and then including it from local, but it does not work somehow, giving some php error inside JavaBridge class... I do not see any difference though.
As suggested by Marc B, used the following code:
$remote_contents = file_get_contents($url);
file_put_contents($local, $remote_contents);
include($local);
Didn't work on first try, but worked after adding this line before the include:
define ("JAVA_SERVLET", "/WordBridge/servlet.phpjavabridge");
Well, this is a problem I have never seen before.
I am trying to stream an FTP file using PHP's fopen() and feof() in order to copy it from one server to my own. This works fine when using normal http:// URLs. However, when using the ftp:// protocol, I'm receiving the following error:
fopen(ftp://.../streaming/planted2.mp4) [0function.fopen0]: failed to open stream: FTP server reports 550 /streaming/planted2.mp4: not a plain file.
Bear in mind that I have confirmed the URL is correct.
If I pop it into my browser's search bar, it always loads correctly.
Following this error, any attempt to use feof() or fread() on the wrapper results in an error complaining that the respective function expects a resource, but that instead a boolean is being provided. This would not be the case if fopen() was not failing.
As the files are quite large (several gigabytes at times) streaming is mandatory. Also, due to the configuration of the server, I need a way to loop through each chunk in order to buffer some output. If I don't, the server holds up. It's a weird configuration on Rackspace's behalf. That's why I'm using feof().
So, without further ado, my question is this: What does the 550 error mean, and what is a "plain file"? If it is a problem with the configuration of the server I am attempting to download from, what are my options, given my limitations?
EDIT
I have determined this is a server issue. However, the problem is still unresolved.
I contacted my boss and our server administrator, and the server guy told me to test this out on a different Windows-based server instead of the Linux-based one I was playing with. My script works with the Windows server, so I have confirmed my script is not in error.
Unfortunately, my boss still wants me to figure out the problem, and find out why it's not working on the Linux box. I have absolutely no idea why, and don't know where to look. Any hints would be greatly appreciated!
I've just come across this issue when trying to get a file from a sco unix server.
Server File Location: /home/user/data/myfile.csv
I can put the below into any browser and it gets the file.
ftp://user:password#host/data/myfile.csv
However if I run the below, I get the same error as you
$f = fopen("ftp://user:password#host/data/myfile.csv", "r");
However, if I put the full path into fopen - it works fine.
$f = fopen("ftp://user:password#host/home/user/data/myfile.csv", "r");
I'm not sure if this will fix it for you, but works for me.