0
我想使用的PhoneGap和笨在服務器端PhoneGap的錯誤沒有上載笨
這個上傳圖片到一個服務器上的文件是PHP代碼
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' '));
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1600';
$config['max_height'] = '1600';
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
echo $error;
//$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
echo "success";
//$this->load->view('upload_success', $data);
}
}
} ?>
這是PhoneGap的代碼
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://mywebsite.com/upload/do_upload"), win, fail, options, true);
這是LO g催化劑
03-06 10:29:52.510: D/FileTransfer(5732): upload file:///mnt/sdcard/Android/data/com.fileupload.test/cache/1362536991781.jpg to http://soovy.me/upload/do_upload
03-06 10:29:52.510: D/FileTransfer(5732): fileKey: file
03-06 10:29:52.510: D/FileTransfer(5732): fileName: 1362536991781.jpg
03-06 10:29:52.510: D/FileTransfer(5732): mimeType: image/jpeg
03-06 10:29:52.510: D/FileTransfer(5732): params: {"value1":"test","value2":"param"}
03-06 10:29:52.510: D/FileTransfer(5732): trustEveryone: true
03-06 10:29:52.510: D/FileTransfer(5732): chunkedMode: false
03-06 10:29:52.510: D/FileTransfer(5732): headers: null
03-06 10:29:52.510: D/FileTransfer(5732): objectId: 1
03-06 10:29:52.540: D/FileTransfer(5732): String Length: 256
03-06 10:29:52.540: D/FileTransfer(5732): Content Length: 23677
03-06 10:29:54.930: D/FileTransfer(5732): got response from server
03-06 10:29:54.930: D/FileTransfer(5732): <p>You did not select a file to upload.</p>
03-06 10:29:54.940: D/CordovaLog(5732): Code = 200
03-06 10:29:54.940: I/Web Console(5732): Code = 200 at file:///android_asset/www/index.html:400
03-06 10:29:54.950: D/CordovaLog(5732): Response = <p>You did not select a file to upload.</p>
03-06 10:29:54.950: I/Web Console(5732): Response = <p>You did not select a file to upload.</p> at file:///android_asset/www/index.html:401
03-06 10:29:54.950: D/CordovaLog(5732): Sent = 23421
03-06 10:29:54.950: I/Web Console(5732): Sent = 23421 at file:///android_asset/www/index.html:402
但是我得到PHP中的錯誤您沒有選擇要上傳的文件但作爲logcat的規定發給23421這樣的圖像發送。我也用一個發送圖像的正常窗體測試了php,它工作正常。
更新:
其他任何人試圖從PhoneGap的上傳上傳使用此代碼
對於普通的PHP從http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap
print_r($_FILES); //to check details of file
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "./uploads/".$new_image_name);
對於笨
if (! $this->upload->do_upload('file'))// file should be stated as dakdad answered
感謝
你是對的,謝謝你的作品 – jhdj 2013-03-06 04:00:01