php - 从 iPhone 上传图像到服务器时出错

标签 php ios mysql iphone

我正在尝试使用 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 代码是

<?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\" />";
}

 ?>

最佳答案

更改上传文件夹的路径

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

至 $uploaddir = getcwd().'/uploads/';

这将解决您的问题

关于php - 从 iPhone 上传图像到服务器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26355507/

相关文章:

ios - 收到状态的CA回调,但事件状态队列为空

ios - 如何比较 Collection View 中单元格的边框颜色(iOS,swift)

php - 如何将数组放入&lt;textarea&gt;

php - 如何匹配 [...] 的正则表达式模式

php - 如何在现有的 Symfony2 应用程序中实现 Sylius OrderBundle

php - 如何使用php与Youtube Api v3赞YouTube视频

mysql - GROUP BY 并排序

php - 使用 FB Graph API 获取所有 Facebook 群组帖子

ios - UIView 动画不重复/突然停止

mysql - 在 Rails 中添加默认值为空字符串的 NOT NULL 列