php - 在钛中将图像上传到服务器时无法读取 php 文件

标签 php ios mysql file-upload titanium

我尝试从图库中获取图像并使用钛网络服务将所选图像上传到服务器。

我使用了下面的代码。但是我收到调试错误:HTTP 错误并且它还显示警告框,如“连接期间出现错误”

此代码在我的开发服务器中运行良好。但它在我的客户端服务器中不起作用。什么原因 ?为什么我的代码不能在我的客户端服务器上运行?

从 android 设备上传文件时文件上传工作正常。但是从 iphone 设备上传文件时它不工作。你能给我一个解决这个问题的想法吗?

为什么我的控制台窗口会出现这个错误。

 function AUF_ADD_File_FolderData () { 
  Titanium.Media.openPhotoGallery({
  success:function(event) {
      var request = Ti.Network.createHTTPClient({ 
               onload : function(e) {
        Ti.API.info(this.responseText);
        Ti.API.info("image pathe"+" "+event.media);
   if(this.responseText == "Successfully file is created"){
             var managefolders =Alloy.createController('manage_folders').getView();
       managefolders.open();  
         }
         else{
             alert(this.responseText); 
         }
    }, 
              onerror: function(e){ 
                  Ti.API.debug(e.error); 
                  alert("There was an error during the connection"); 
              }, 
              timeout:20000, 
                 });    
                   var uploadabc = event.media.imageAsResized(400 , 400);
                       request.open("POST",url+"client/manager/at_manager_create_common_file.php"); 

                 var params = ({"manager_id": manager_id,"file": uploadabc,}); 
               // var params = ({"manager_id": manager_id,"file": event.media,});   
              request.send(params); 

},

    cancel:function() {
        // called when user cancels taking a picture
    },
    error:function(error) {
        // called when there's an error
        var a = Titanium.UI.createAlertDialog({title:'Camera'});
        if (error.code == Titanium.Media.NO_CAMERA) {
            a.setMessage('Please run this test on device');
        } else {
            a.setMessage('Unexpected error: ' + error.code);
        }
        a.show();
    },
    saveToPhotoGallery:false,
    // allowEditing and mediaTypes are iOS-only settings
    allowEditing:true,
    mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
}

编辑:

这是 php 文件:

    <?php  

$request            = base64_decode($_POST['jsondata']);

$data               = json_decode($request,true);
$manager_id         = $data['manager_id'];
$file_name          = $data['file_name'];
$source             = base64_decode($data['source']);

include "db_connect.php";
// connecting to db
$db = new DB_CONNECT();

$result     = mysql_query("SELECT * from at_common_files WHERE user_id = '$manager_id'  and file_name = '$file_name'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
    $response='{"Error":"1","Message":"Filename already existed"}';
    echo $response;
} else {
    $upload_dir = 'common_files/'.$manager_id."_".$file_name;

    file_put_contents($upload_dir,$source);
    $qugery     = mysql_query("insert into at_common_files (user_id,file_name) values ($manager_id, '$file_name') ");
    $response   = '{"Error":"0","Message":"Successfully file is created"}';
    echo $response;
}

?>

编辑:

出现以下错误:

: [DEBUG] HTTP 错误 : [INFO] 错误 {"type":"error","source":{"cache":false},"code":404,"error":"HTTP error","success":false

如果我调用相同的 url 并单独传递一个 manager_id,我得到的结果很好。如果我传递了 manager_id 和文件,这次只会收到 Http 错误。我找不到确切的问题。因为相同的钛代码和 php 代码(开发服务器)工作正常并且图像正在上传到开发服务器文件夹。但我已将相同的 php 文件移动到我的客户端服务器。现在它不工作了。同样的网络服务 url 在浏览器和 android 中工作正常。它只在 iphone 中不起作用。所以我找不到问题出在哪里?你能给我一个解决方案吗?

编辑: 请引用以下链接:

http://developer.appcelerator.com/question/174462/image-not-uploading-from-iphone#comment-224007

我遇到了完全相同的问题。你能给我一个解决方案吗。

最佳答案

我发现了很多这样的问题(例如 The 'Passive' connection '<appname>' access to protected services is denied )。

答案总是:
“这个错误就是所谓的“红鲱鱼”。这是一个具有误导性的线索。HID 并不是影响您的应用程序的真正错误。应该有其他消息可以指示正在发生的事情。” 所以看看是否有其他错误信息描述了您的问题。

例如,尝试转义您在 sql 语句中使用的文件名:

$file_name = mysql_real_escape_string($data['file_name']);

关于php - 在钛中将图像上传到服务器时无法读取 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27684189/

相关文章:

ios - 如何在不显示中间 View 的情况下展开多个 View

php - 与用户关联的 ACF update_field

php - 是否可以从扩展中调用 PHP_FUNCTION

php - ZendFramework - 如何声明静态全局常量,以使其在我的所有 Controller 和模型中可用?

mysql - 如何将多行转换为一行?

mySQL两次连接同一个表

mysql - 仅当该表中所有其他行的值为 0 时才插入 mysql 行

php - 如何使用 PHP 上传任何文件类型的 BLOB

iphone - 如何在应用程序中播放带有音乐文件的播放列表?

ios - 如何在耳机的两个芽之间切换音频输出