在接收文件时要写什么脚本


What script to write on receiving file?

我已经创建了一个脚本,按照这里的教程拍摄照片并将其传输到远程服务器。这似乎是可行的,但我非常不确定在这个脚本的接收端写什么,即:我需要在服务器上的php文件上放什么。

最终,我想将图像写入服务器上的一个目录,然后将其路径保存到数据库中。

有人知道我应该找什么函数来做这件事吗?我在Cordova手册中找不到任何东西,也不知道该怎么办。

我应该只使用PHPGET还是REQUEST函数?

(我正在XCode中为iOS创建一个应用程序)

我的代码是:

     smallImage.src = "data:image/jpeg;base64," + imageURI;
              var fail, ft, options, params, win;
              // callback for when the photo has been successfully uploaded:
              var success =  function(response) {
                  alert("Photo Saved");
              };
              // callback if the photo fails to upload successfully.
              var fail = function(error) {
                  alert("An error has occurred: Code = " + error.code);
                  alert(FileTransferError.CONNECTION_ERR);
              };
              options = new FileUploadOptions();
              // parameter name of file:
              options.fileKey = "my_image";
              // name of the file:
              options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
              // mime type:
              options.mimeType = "text/plain";
              params = {
                  val1: "some value",
                  val2: "some other value"
              };
              options.params = params;
              ft = new FileTransfer();
              ft.upload(imageURI, 'http://mysite.com/appimages/recieve.php', success, fail, options);

(注意:receive.php当前为空)

您可以使用以下代码保存上传的文件

<?php
$target_path = "tmp/";
if ($_FILES["my_image"]["error"] > 0){
echo "Error: " . $_FILES["my_image"]["error"] . "<br>";
}
else{ 
    if (file_exists($target_path . $_FILES["my_image"]["name"])){
        echo $_FILES["my_image"]["name"] . " already exists. ";
    }
    else{
        move_uploaded_file($_FILES["my_image"]["tmp_name"], $target_path . $_FILES["my_image"]["name"]);
        echo "Stored in: " . $target_path . $_FILES["my_image"]["name"];
    }
}
?>