NSData 到文件 PHP
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑将数据作为 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.