2014-10-14 6 views
0

PHP를 사용하여 서버에 사진을 업로드하려고합니다. 사실 나는 ASIFormDataRequest와 함께 mysql 데이터베이스 요청에 이름을 저장 한 서버에 사진을 업로드하려고합니다. 로컬 서버 디렉토리 폴더에 사진을 업로드하고 싶습니다.아이폰에서 서버에 이미지를 업로드하는 중 오류가 발생했습니다.

if ([arrImages count] > 0) { 
    NSString *strURL = @"http://localhost/ApneAreaMein/upload_file.php"; 

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]]; 

[request setDelegate:self]; 
[request setPostValue:@"This is sample text..." forKey:@"company_logo"];//Here write down the text which will be sent. 

for (int i = 0; i < [arrImages count]; i++) { 

    [request addData:[arrImages objectAtIndex:i] withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:[NSString stringWithFormat:@"image%d", i + 1]]; 
} 
[request startAsynchronous]; 
} 
else { 
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Please   select images..." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
[alertView show]; 
} 

내 PHP는 코드 $ uploaddir =에 getcwd()에

$uploaddir = 'http://localhost/apneareamein/uploads/'; 

에서 업로드 폴더의

<?php 

$con = mysql_connect('localhost','root'); 
mysql_select_db('apnemein_forms',$con); 

$uploaddir = 'http://localhost/apneareamein/uploads/'; //folder named upload, where  image will be saved (same dir as this file) 
$file = basename($_FILES['company_logo']['company_logo']); 

$uploadfile = $uploaddir . $file; 

if (move_uploaded_file($_FILES['company_logo']['tmp_name'], $uploadfile)) 
{ 
echo "File not uploaded"; //i'm not sure about this, but it works for me like this 
} 
else 
{ 
echo "<img src=\"uploads/photopicker.jpg\" />"; 
} 

?> 

답변

0

변경 당신에게 경로 '/ 업로드 /.';

그러면 문제가 해결됩니다.

관련 문제