アップロードのネイティブ コードは次のようになります。
- (void)uploadSomethingFiveTimes:(NSURL *)url
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"medelix.db" ofType:nil];
NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath: filePath];
ASINetworkQueue *myQueue=[[ASINetworkQueue alloc] init] ;
[myQueue cancelAllOperations];
[myQueue setUploadProgressDelegate:myProgressIndicator];
[myQueue setDelegate:self];
[myQueue setRequestDidFinishSelector:@selector(queueComplete:)];
int index;
NSData *myData=nil;
int Filedata= [file seekToEndOfFile];
Filedata=(Filedata/3);
[file seekToFileOffset:0];
NSLog (@"Offset = %llu", [file offsetInFile]);
for (index=3; index>0; index--) {
myData = [file readDataOfLength: Filedata];
NSString *x1 = [[[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"responseData=%@",x1);
NSLog (@"Offset = %llu", [file offsetInFile]);
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(postFinished:)];
[request setDidFailSelector:@selector(postFailed:)];
[request timeOutSeconds];
[request setNumberOfTimesToRetryOnTimeout:2];
[request setPersistentConnectionTimeoutSeconds:120];
[request setShowAccurateProgress:YES];
NSString *ServerFileName=[NSString stringWithFormat:@"%@_%@",[self getcurrentdateTime],@"medelix.db"];
[request setData:myData withFileName:ServerFileName andContentType:@"application/x-www-form-urlencoded" forKey:@"uploadedfile"];
NSString *x = [[[NSString alloc] initWithData:[request responseData]encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"responseData=%@",x);
⠀
[myQueue addOperation:request];
}
[myQueue go];
}
- (void)postFinished:(ASIFormDataRequest *)request
{
// NSData *newStringData = [request responseData];
NSString *x = [[[NSString alloc] initWithData:[request responseData]encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"Post Success %d [request responseData]=%@",[request inProgress],x);
NSLog(@"Post Success %@" ,[request timeOutSeconds]);
}
- (void)postFailed:(ASIFormDataRequest *)request
{
NSLog(@"Post Failed %d",[request inProgress]);
NSLog(@"Post Failed %@",[request error]);
}
- (void)queueComplete:(ASINetworkQueue *)queue
{
//[queue requestsCount];
// NSLog(@"Max:%d", );
NSLog(@"Max: %f, Value: %f", [myProgressIndicator progress],[myProgressIndicator progress]);
}
サーバー側のコードは次のようになります:--
+
<?php
$target_path = '/Applications/XAMPP/xamppfiles/htdocs/myupload/';
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$myFile=$_FILES['uploadedfile']['name'];
echo $myFile." 1st line \n";
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else{
echo "There was an error uploading the file, please try again!";
}
if(file_exists($myFile))
{
$file="server_".$_FILES['uploadedfile']['name'];
//exec("chmod $target_path 0777");
if( chmod($_FILES['uploadedfile']['tmp_name'], 777))
{
echo "YES!";
}
if( chmod($target_path, 777))
{
echo "YES";
}
else
{
echo "NO";
}
$fh = fopen($target_path,'r');
// $file='/Applications/XAMPP/xamppfiles/htdocs/myupload/server';
$ab=file_put_contents($file, fread($fh,filesize($target_path)),FILE_APPEND);
echo "Fread".$ab;
// fwrite($fh,"\n");
fclose($fh);
echo $fh." 2st line \n".$target_path." \n";
}
unlink($target_path);
?>