Php 使用NSURLConnection上载图像时出错

Php 使用NSURLConnection上载图像时出错,php,objective-c,post,Php,Objective C,Post,我正在尝试使用NSURLConnection上传图像,这里的POST方法就是我目前所拥有的 NSData* imageData =UIImageJPEGRepresentation(_imageView.image, 90); NSString * urlString =@"mywebiste.myphpfile.php"; NSMutableURLRequest * request=[[NSMutableURLRequest alloc] init]; [request setURL:[

我正在尝试使用NSURLConnection上传图像,这里的POST方法就是我目前所拥有的

  NSData* imageData =UIImageJPEGRepresentation(_imageView.image, 90);
NSString  * urlString =@"mywebiste.myphpfile.php";
NSMutableURLRequest * request=[[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary=@"---------------------------14737809831466499882746641449";
NSString *contentType=[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"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]];
[request setHTTPBody:body];
NSData * returnData=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString=[[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(returnString);
这是我正在调用的php文件

<?PHP

    $uploaddir = './';      //Uploading to same directory as PHP file
    $file = basename($_FILES['userfile']['name']);
    $uploadFile = $file;
    $randomNumber = rand(0, 99999);
    $newName = $uploadDir . $randomNumber . $uploadFile;


    if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
        echo "Temp file uploaded. \r\n";
    } else {
        echo "Temp file not uploaded. \r\n";
    }

    if ($_FILES['userfile']['size']> 300000) exit("Your file is too large.");
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) {
        $postsize = ini_get('post_max_size');   //Not necessary, I was using these
        $canupload = ini_get('file_uploads');    //server variables to see what was
        $tempdir = ini_get('upload_tmp_dir');   //going wrong.
        $maxsize = ini_get('upload_max_filesize');
        echo "http://www.mywebsite.com/{$file}" . "\r\n" . $_FILES['userfile']['size'] . "\r\n" . $_FILES['userfile']['type'] ;
    }

?>

我从中得到的错误有点不具体

 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at 
webmaster@mywebsite.com to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html> 

500内部服务器错误
内部服务器错误
服务器遇到内部错误或错误
配置错误,无法完成
你的要求

请通过以下地址与服务器管理员联系: webmaster@mywebsite.com要通知他们此错误发生的时间, 以及您在此错误之前执行的操作

有关此错误的详细信息,请参阅 在服务器错误日志中

此外,未找到404 尝试使用ErrorDocument处理请求时遇到错误

以前有没有人遇到过这种情况,有没有办法解决? 我需要弄清楚这件事,但我不知道该怎么办。
提前谢谢

您应该检查服务器错误日志,以查找触发500 HTTP响应的特定PHP错误。顺便说一句,检查您的变量
$uploaddir
,当您引用它时,您正在调用它
$uploaddir
。谢谢,但我已经检查了错误日志及其空值