NSData 到文件 PHP

发布于 2024-12-06 00:20:33 字数 820 浏览 0 评论 0原文

我有 NSData,我正在“发布”到我网站上的 PHP 文件,从该 NSData,我将其写入文件。然而,文件的内容是 NSData 的字符串(字母和数字的范围)而不是解析的数据。如何在 PHP 中将 NSData 解析为字符串,然后将该字符串的内容写入文件?

到目前为止,这是我的代码:

$filename = $_POST['username'] . "_iCal_" . $newID . ".ics";
$File = $upload_path . $filename; 
$Handle = fopen($File, 'w');
$Data = urldecode($_POST['ical']);
$Data = str_replace (" ", "", $Data);
fwrite($Handle, $Data) or die("s");
fclose($Handle) or die("s");


[NSKeyedArchiver archivedDataWithRootObject:event] //event is an NSObj-- Subclass with NSCoding etc... implemented
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:MPiCalUpload_URL]];
[request setTimeOutSeconds:MPiCalRetriever_timeout];
[request setPostValue:_username forKey:@"username"];
[request setPostValue:data forKey:@"ical"];

I have NSData that I am 'POST'ing to a PHP file on my site, from that NSData, I am writing it to a file. However, the file's contents are the string of NSData (range of letters and numbers) rather than the parsed data. How can I parse the NSData to a string in PHP and then write the contents of that string to a file?

Here is my code so far:

$filename = $_POST['username'] . "_iCal_" . $newID . ".ics";
$File = $upload_path . $filename; 
$Handle = fopen($File, 'w');
$Data = urldecode($_POST['ical']);
$Data = str_replace (" ", "", $Data);
fwrite($Handle, $Data) or die("s");
fclose($Handle) or die("s");


[NSKeyedArchiver archivedDataWithRootObject:event] //event is an NSObj-- Subclass with NSCoding etc... implemented
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:MPiCalUpload_URL]];
[request setTimeOutSeconds:MPiCalRetriever_timeout];
[request setPostValue:_username forKey:@"username"];
[request setPostValue:data forKey:@"ical"];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2024-12-13 00:20:33

考虑将数据作为 Base64 字符串传递。搜索“NSData Base64”,您会发现很多示例。然后在 PHP 端,使用 base64_decode() 取回字节。

Consider passing the data as a Base64 string. Search SO for "NSData Base64", you'll find plenty of examples. Then on the PHP side, use base64_decode() to get the bytes back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文