0

このトピックに関する多くの投稿を見てきましたが、問題の解決に役立つものはありませんでした。サーバーに保存されている画像をダウンロードするために使用する webserver に download.php ファイルがあります。PHP は、タスクを 2 つのステップに分割することでこれを行います。
最初のステップは、ユーザー情報を送信することです。php はユーザーに関連付けられた画像の ID を返します。これらの ID に基づく 2 番目のステップでは、同じ php ページに別のリクエストを送信し、特定の ID の画像を 1 つずつリクエストします。
このアプローチは、html または私の Android コードで使用するとうまく機能するため、php に問題はないと確信しています。

iOSコードからphpにリクエストを送信すると、画像IDを取得する最初のステップはうまくいきますが、画像のリクエストはまったく機能しません。didReceieveData コールバックが呼び出されることはありません。これが私がやっていることです -

- (void)downloadImages:(NSInteger)imageNo{
    NSString *post = [NSString stringWithFormat:@"user=%@&download=%@&imageId=%d", userName, @"true",imageNo];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
                                    initWithURL:[NSURL
                                                 URLWithString:@"MYWEBSERVER/download.php"]];

    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];

    currentDownMode = DOWN_IMAGE;

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

これが私のphpページにあるものです-

function download()
{
    global $folder_path, $user_id, $image_table, $sql_folder_path;
    $fileID = $_POST["imageId"];
    $sql="SELECT fileName,filePath FROM $image_table WHERE fileId='$fileID'";
    $query = mysql_query($sql) or die($sql . ' - ' . mysql_error());
    $row = mysql_fetch_array($query);
    $im = file_get_contents("../" . $row[1] . $row[0]);
    header('content-type: image/gif'); 
    echo $im;
}
4

0 に答える 0