Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php mysql Xcode从应用程序上传图像并另存为文件系统和数据库_Php_Ios_Mysql_Iphone_Xcode - Fatal编程技术网

如何使用php mysql Xcode从应用程序上传图像并另存为文件系统和数据库

如何使用php mysql Xcode从应用程序上传图像并另存为文件系统和数据库,php,ios,mysql,iphone,xcode,Php,Ios,Mysql,Iphone,Xcode,我试图在数据库和服务器中上传图像,但在文件夹中我得到了图像,但在上传图像时总是只有一个,替换之前上传的现有图像,甚至没有保存在数据库中。我想将图像保存在数据库和文件系统中,以备将来在web上使用。我知道我或者我遗漏了一些东西,但我不知道我是新的,请帮助我的代码是什么 NSData *imageData = UIImageJPEGRepresentation(self.imageview.image,90); NSString *urlString = @"htt

我试图在数据库和服务器中上传图像,但在文件夹中我得到了图像,但在上传图像时总是只有一个,替换之前上传的现有图像,甚至没有保存在数据库中。我想将图像保存在数据库和文件系统中,以备将来在web上使用。我知道我或者我遗漏了一些东西,但我不知道我是新的,请帮助我的代码是什么

 NSData *imageData = UIImageJPEGRepresentation(self.imageview.image,90);
                NSString *urlString = @"http://befirstwin.com/upload.php";
                NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
                [request setURL:[NSURL URLWithString:urlString]];
                [request setHTTPMethod:@"POST"];

                NSString *boundary = @"---------------------------14737809831466499882746641449";
                NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
                [request addValue:contentType forHTTPHeaderField:@"Content-Type"];
                // file
                NSMutableData *body = [NSMutableData data];
                [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

                [body appendData:[@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
                //[body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n", uname]] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[NSData dataWithData:imageData]];
                [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
                // close form
                [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                // set request body
                [request setHTTPBody:body];
                //return and test
                NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
                NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:returnString delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                [alert show];
对于php

<?php

//my connection


$abdb = $_FILES['userfile']; //getting image Here //getting textLabe Here 
    $target_path = "abdbphoto/";
     if(move_uploaded_file($abdb['tmp_name'], $target_path . basename( $abdb['name'])))

    { echo "The file ". basename( $abdb['name']). " has been uploaded"; } 

    else 

    {
     echo "There was an error uploading the file, please try again!";
     } 
   if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0) { 

      // Temporary file name stored on the server
      $tmpName  = $_FILES['userfile']['tmp_name'];  
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);



if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

      // Create the query and insert
      // into our database.
     $query = "INSERT INTO pictures (image ) ".
"VALUES ('$content')";
      $result = mysql_query($query);

if(!$result)
{
die("we have problem");
}
else
{
      // Print results
      print "Thank you, your file has been uploaded.";
}
}
else {
   print "No image selected/uploaded";
}   
mysql_close();
?>

请检查它,并请建议我缺少什么和图像数据库文件,我有我的电子邮件id,我不知道如何发送它在同一时间。。提前感谢

任何人都会知道我做错了什么,如果是,请建议!!我被难住了@阿什·卡卡德