PHP服务器从Phonegap和Jquery上传图像

PHP服务器从Phonegap和Jquery上传图像,php,javascript,jquery,cordova,Php,Javascript,Jquery,Cordova,好的,我有一个上传图片的小应用程序(使用phonegap,Jquery)。我使用jquery通过AJAX处理上传。正在发送图像,但我不确定如何在服务器端正确处理它。欢迎有任何想法!以下是我目前的代码: PHP: 请检查您正在使用fwrite创建映像的目录的写入权限。长话短说,我需要设置联机服务器文件夹的权限 对于任何使用phonegap和访问URL(显然对于AJAX来说是必不可少的)的新iphone开发人员来说,也值得一提。必须在Xcode项目中设置URL(PhoneGap.plist包含存储外

好的,我有一个上传图片的小应用程序(使用phonegap,Jquery)。我使用jquery通过AJAX处理上传。正在发送图像,但我不确定如何在服务器端正确处理它。欢迎有任何想法!以下是我目前的代码:

PHP:


请检查您正在使用fwrite创建映像的目录的写入权限。

长话短说,我需要设置联机服务器文件夹的权限

对于任何使用phonegap和访问URL(显然对于AJAX来说是必不可少的)的新iphone开发人员来说,也值得一提。必须在Xcode项目中设置URL(PhoneGap.plist包含存储外部URL的数组)

这对一些人来说可能是显而易见的,但即使是PhoneGap似乎也没有很好的记录(或者至少我在疯狂的谷歌搜索中没有看到)。我学习的维基教程没有提到这一点

有关详细信息,请参见图

<?php 
    ////////THE PROBLEM AREA I THNK//////////
    if ($_REQUEST['image']) {

            // convert the image data from base64
            $imgData = base64_decode($_REQUEST['image']);

            // set the image paths
            $file = '/uploaded_files/' . md5(date('Ymdgisu')) . '.jpg';
            $url = 'http://creativetree.co/creativetreeAlpha' . $file; 

            // delete the image if it already exists
            if (file_exists($file)) { unlink($file); }

            // write the imgData to the file
            $fp = fopen($file, 'w');
            fwrite($fp, $imgData);
            fclose($fp);
    }

    echo "<h1>Page is online</h1>";
    echo "<p>Nothing special just a first go at phonegap! </p>";
    echo "<h2>Contents of uploaded_files Folder to show iphone upload</h2>";

    $dir = '/homepages/22/d397139588/htdocs/creativetreeAlpha/uploaded_files';

    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) { 
            if ($file != "." && $file != "..") { 
                echo "$file\n";
                echo "<br>";
            } 
        }
        closedir($handle); 
    }
   ?>
<script>
function onBodyLoad() {
document.addEventListener("deviceready",onDeviceReady,false);
}
</script>
</head>
<body onload="onBodyLoad()">
<body>
        <h1>Upload an image</h1>

        <div id="upload"    
        <input type="button" class="send-image" value="camera" />
        <input type="button" class="send-image" value="library" />
        <img style="width:60px; height:60px" id="image" src="" />
        </div>

<div id="output"></div>
</body>
</html>
$(document).ready(function(){
  $(document).bind('deviceready', function(){

  function sendImage(src) {

    src = (src == 'library') ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.CAMERA;
    navigator.camera.getPicture(success, fail, {quality: 45, sourceType: src});

                             function success(imageData) {
                             var url = 'http://creativetree.co/creativetreeAlpha/mobileImageUpload.php';
                             var params = {image: imageData};

                             // send the data
                             $.post(url, params, function(data) {
                                     alert('sent');
                                     // Display the selected image on send complete
                                     $('#image').attr('src', 'data:image/jpeg;base64,' + params['image']);     
                             });
                             }
}

  function fail(message) { alert(message); }

  $('.send-image').click(function () { sendImage($(this).val()); });

  });
});