2013-12-18 4 views
0

나는 다음과 같은 서버아이폰

에 이미지를 업로드하려고에서 PHP 서버에 이미지를 업로드 PHP 코드가

$directoryPath = "userId_" . $userId; 
    $this->makeDir("uploads/images/" . $directoryPath); 
    $this->makeDir("uploads/thumbs/" . $directoryPath); 

    $val = $userId .'_' . time() . ".jpg"; 
    $mainPath = "uploads/images/" . "image_" . $val; 
    $thumbPath = "uploads/thumbs/" . "thumb_" . $val; 

    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $mainPath)) 
     return true; 
    else 
     return false; 


    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $mainPath)) 

가 false를 반환된다

// create request 
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; 
    [request setHTTPShouldHandleCookies:NO]; 
    [request setTimeoutInterval:30]; 
    [request setHTTPMethod:@"POST"]; 

    NSString *boundary = @"0xKhTmLbOuNdArY"; 
    NSString *url = [NSString stringWithFormat:POST_URL,BASE_URL, [Utilities myUserId],@"", TYPE_IMAGE]; 

    // set Content-Type in HTTP header 
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; 
    [request setValue:contentType forHTTPHeaderField: @"Content-Type"]; 

    // post body 
    NSMutableData *body = [NSMutableData data]; 

    NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 
    [params setObject:self.chatBox.text forKey:@"comment"]; 

    // add params (all params are strings) 
    for (NSString *param in params) 
    { 
     [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", param] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[[NSString stringWithFormat:@"%@\r\n", [params objectForKey:param]] dataUsingEncoding:NSUTF8StringEncoding]]; 
    } 

    if (picData) 
    { 
     [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"image.jpg\"\r\n", @"uploadedfile"] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:picData]; 
     [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
    } 

    [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 

    // setting the body of the post to the reqeust 
    [request setHTTPBody:body]; 

    // set URL 
    [request setURL:[NSURL URLWithString:url]]; 
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    if (connection) 
    { 
     [self dismissKeyboard]; 
    } 

아이폰과 PHP 코드를입니다 . 무엇이 잘못 될 수 있습니다. 당신이 제출하는 파일 크기는 php.ini 파일에서 설정이 upload_max_filesize를 초과

["userfile"]=> 
    array(5) { 
    ["name"]=> 
    string(6) "dr.jpg" 
    ["type"]=> 
    string(0) "" 
    ["tmp_name"]=> 
    string(0) "" 
    ["error"]=> 
    int(1) 
    ["size"]=> 
    int(0) 
    } 
+0

디렉토리 업로드/이미지 및 업로드/승인이 이루어 집니까? 그렇게 할 권한이 있습니까? – user602525

+0

그들은 이미 만들어졌으며, 나는 이미 Permissions 777을 설정했다. 내가 테스트 한 isse가 무엇인지 모르겠다. \t \t \t $ file = basename ($ _ FILES [ 'userfile'] [ 'name']) ; 올바른 이름을 제공하므로 업로드가 잘됩니다 –

+0

if 문 앞에 var_dump ($ _ FILES)가 있으면 출력은 무엇입니까? – user602525

답변

1

, 이것은 당신의 위해서 var_dump에 의해 결정될 수있다() 에러 키를 검사하는이 경우 = 1

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. 
에서

: - 워드 프로세서

기본이 upload_max_filesize는 2메가바이트

http://www.php.net/manual/en/features.file-upload.errors.php

일반적인 함정이다

http://www.php.net/manual/en/features.file-upload.common-pitfalls.php

+0

php.ini를 편집하고 기본 값을 200M으로 변경했지만 결과는 동일합니다. 오류가 여전히 동일합니다 : ( –

+0

오류 키는 여전히 int (1)입니까? 업로드하려는 파일의 크기는 무엇입니까? – user602525

+0

2697777 바이트, mabye 아파치를 다시 시작해야합니까? –