I am sending same data with PHP cURL. But I am using "\\n" character in a text area and it prints "Empty reply from server" . Unless I use "\\n", it is working.
For example:
<form action="gonder.php" method="post">
<textarea name="content" rows=23 cols=70></textarea>
<input class="button" type="submit" value="Kaydet">
</form>
And my gonder.php file:
<?php
if($_POST['content'] != ""){
$ch = curl_init('http://address/page.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'bilgi='.$_POST['content']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch) or die(curl_error($ch));
header("Location: index.php?olay=2");
}
?>
Additional information: My file has single-quotes at the end.
How can I solve this problem?
veriler.txt:
araba
ev
dükkan
mağaza
veriler.txt is in another server and I want to rewrite it with a textarea using post method
curl will encode for you if you pass an array, or you can use urlencode() in your existing code:
$content = array('bilgi' => $_POST['content']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
I think that you need to send the text as HTML using this functions nl2br(htmlentities()) :
curl_setopt($ch, CURLOPT_POSTFIELDS, 'bilgi='.nl2br(htmlentities($_POST['content'])));
as
araba<br>
ev<br>
Then when you receive it extract the text from html code using str_replace( "<br>" , "\\n" , $_POST['bilgi']);
, And write it into you file veriler.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.