表单文件上传phonegap [英] form file upload phonegap

查看:85
本文介绍了表单文件上传phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人上传一个非常基本的,但工作版本的文件上传脚本,用javascript写成,然后将是phonegap友好

Please could someone upload a very basic but working version of a file upload script written in javascript that will then be phonegap friendly

我拖网了但是大多数的东西都是过时的,或者更新的东西似乎假定你知道所有关于phonegap的内部工作

I've trawled the internet trying to figure it out but most of the stuff out there is either out of date or the newer stuff seems to presume that you know all about the inner workings of phonegap

我掌握如何传输文件,但我不知道如何探索/访问手机/平板电脑文件系统来寻找所需的文件上传

I grasp how to transfer the file but I cannot figure out how to explore/access the phones/tablets file system to look for the desired file for upload

在一个完美的世界,phonegap会识别表单文件上传按钮并将其转换,所以它的工作原理与在网络浏览器中一样,但它似乎只是禁用它。

In a perfect world phonegap would recognise the form file upload button and convert it so it works the same as if it were in a web browser but all it seems to do is disable it.

我使用php作为服务器端。

I'm using php as the sever side. I've spend days trying to understand how to do it... any help would be massively appreciated!

推荐答案

请尝试以下操作。先获取文件,然后将文件路径和类型作为参数传递。

Try like following. Get the file first and pass the file path and type as parameters.

function gotFile(file) {
    uploadFile(file.fullPath,file.type);
}

function uploadFile(imageURI,type) {

   var options = new FileUploadOptions();
   options.fileKey = "file";
   options.fileName = imageURI;
   options.mimeType = type;
   var params = {};
   //params.filePath = "files/";
   options.params = params;

   var ft = new FileTransfer();
   ft.upload(imageURI, "http:/www.xx.com/fileUpload.php",function onFileTransferSuccess(e){
       alert("File  Success");  

   }, fail, options);
}

您的PHP服务器端函数是(fileUpload.php):

your PHP server side function is like(fileUpload.php):

<?php
$new_image_name = "file.pdf";


$type = $_FILES["file"]["type"];
$name = $_FILES["file"]["name"];
//$paramValue = $_POST['value1'];


move_uploaded_file($_FILES["file"]["tmp_name"], "your storage location".$new_image_name);
?>

让我知道任何困难。

这篇关于表单文件上传phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆