Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像未上传到服务器,PHP问题?_Php_Iphone_Xcode_Ipad - Fatal编程技术网

图像未上传到服务器,PHP问题?

图像未上传到服务器,PHP问题?,php,iphone,xcode,ipad,Php,Iphone,Xcode,Ipad,所以我开发了一个将图像上传到php服务器的应用程序,但它不起作用。我点击上传按钮,没有上传任何东西。目录不重要,如果我必须更改它们以使其工作,我会的。谢谢 这是我的密码 //over here NSString *urlString = @"image8photo.com/photo/php.php"; // setting up the request object now NSMutableURLRequest *request = [[[NSMutableURLRequest allo

所以我开发了一个将图像上传到php服务器的应用程序,但它不起作用。我点击上传按钮,没有上传任何东西。目录不重要,如果我必须更改它们以使其工作,我会的。谢谢

这是我的密码

//over here 
NSString *urlString = @"image8photo.com/photo/php.php";

// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

/*
 add some header info now
 we always need a boundary when we post a file
 also we need to set the content type

 You might want to generate a random boundary.. this is just the same 
 as my output from wireshark on a valid html post
 */
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

/*
 now lets create the body of the post
 */
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];

// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(returnString);
}

@结束

servor上的Php脚本

$uploaddir = '/storage/'; $file = basename($_FILES['userfile']['name']); $uploadfile =         $uploaddir . $file; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {   echo "image8photo.com/storage {$file}"; }

请求是否曾经发送到服务器?你能看看服务器日志来检查对PHP脚本的访问吗?事实上,我甚至在错误日志中没有看到任何东西……打印$文件,看看你的控制台在Xcode中是否显示了任何东西。它应该向您显示一个带有文件名和一些其他信息的数组。