Hai Truong IT
Hai Truong IT

Reputation: 4187

fopen() can't write with error "HTTP wrapper does not support writeable connections"

I have a file with url: http://localhost:8080/cache/a66b311547bf3da88f01139271d5bb50.txt And in php I using code:

$file = "http://localhost:8080/cache/a66b311547bf3da88f01139271d5bb50.txt"
$output = serialize($data);
$fp = fopen($file, "w");
fputs($fp, $output);
fclose($fp);

When run code, is error

Warning: fopen(http://localhost:8080/cache/a66b311547bf3da88f01139271d5bb50.txt): failed to open stream: HTTP wrapper does not support writeable connections ...

How to fix it?

Upvotes: 0

Views: 23085

Answers (5)

Mohsin Shoukat
Mohsin Shoukat

Reputation: 1250

Login to your webmin and give that folder to write permission and in your code set absolute path like this.

if($_SERVER['HTTP_HOST'] != 'localhost'){//for live server
   $file = fopen('/var/www/html/etijarat.pk/feed/file.csv', 'w');
}else{// for your local
    $file = fopen('./feed/file.csv', 'w');
}

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157876

$file = $_SERVER['DOCUMENT_ROOT']."/cache/a66b311547bf3da88f01139271d5bb50.txt";
$output = serialize($data);
file_put_contents($file,$output);

Upvotes: 1

Magic
Magic

Reputation: 1196

fopen() allows read-only access to files/resources via HTTP 1.0, using the HTTP GET method.
You should not use the mode 'w'

$fp = fopen($file, "w");

Please change to 'r'

$fp = fopen($file, "r");

Upvotes: 0

benedict_w
benedict_w

Reputation: 3608

You cannot write using http, you have to use the local file system to write files.

e.g. see http://php.about.com/od/advancedphp/ss/file_write_php.htm

Upvotes: 3

xdazz
xdazz

Reputation: 160883

You are not allowed to write something to an online file.

What you could do is download the file, and write something to it.

Upvotes: 0

Related Questions