我对php完全陌生,需要一些脚本的帮助。当打开的东西很好的时候,不知道为什么写不起作用。我收到的文件是使用- (NSData *)compress:(NSData *) 从这个例子压缩的,后者使用libz.dylib框架。
代码:
<?php
error_reporting(E_ALL);
$dir = "upload/";
if(!file_exists($dir)){
mkdir($dir);
}
$target = $dir . basename($_FILES['uploaded']['name']);
$zip = $target . ".gz";
$file = $target . ".jpeg";
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $zip))
{
$arr = gzfile($zip);
if(is_writable($dir)){
if(! $fh = fopen($file, 'w')){
echo "NO - cannot open file ($file)";
exit;
}
foreach($arr as $value){
if(fwrite($fh, $value) === FALSE){
echo "NO - failed to write to file ($file)";
exit;
}
}
fclose($fh);
echo "YES - successfully written to file ($file)";
}
else{
echo "NO - folder ($dir) not writable";
}
}
else {
echo "NO - unable to move_uploaded_file";
}
?>减压不管用。post请求也与上面的示例相同。有人知道怎么回事吗?这个例子中的压缩方法使用的是什么压缩?(放气、压缩或其他东西)
文章的代码如下所示:
- (NSURLRequest *)postRequestWithURL: (NSURL *)url
data: (NSData *)data // IN
boundry: (NSString *)boundry // IN
{
// from http://www.cocoadev.com/index.pl?HTTPFileUpload
NSMutableURLRequest *urlRequest =
[NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:
[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundry]
forHTTPHeaderField:@"Content-Type"];
NSMutableData *postData =
[NSMutableData dataWithCapacity:[data length] + 512];
[postData appendData:
[[NSString stringWithFormat:@"--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:
[[NSString stringWithFormat:
@"Content-Disposition: form-data; name=\"%@\"; filename=\"test%d\"\r\n", FORM_FLE_INPUT, counter++]
dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:
[@"Content-Type: application/gzip\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:
[@"Content-Encoding: gzip\r\n\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:data];
[postData appendData:
[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPBody:postData];
return urlRequest;
}基本上和cocoadev的例子一样,但是我增加了
[postData appendData: [@"Content-Type: application/gzip\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData: [@"Content-Encoding: gzip\r\n\r\n"dataUsingEncoding:NSUTF8StringEncoding]]; 因为我认为这有助于gfile($file),但是当我试图在终端中对.gz进行压缩时,仍然会得到错误的 gzip : upload/test1.gz:而不是gzip格式的
我还在本站上读到,如果我向HTTP请求中添加内容-Type= gzip (正如我前面所做的那样),Integration将解压缩HTTP主体,但我也无法让它工作。(我在cocoadev的示例中使用了非常简单的php-script,因为我不需要php--stuff中的-stuff)。
发布于 2011-08-03 08:21:33
尝试启用警告和通知输出。它可以帮助你获得更详细的信息。刚把
error_reporting(E_ALL);在代码的第一行
https://stackoverflow.com/questions/6923469
复制相似问题