我正在使用Phone Gaps(Cordova 2.1)文件传输API将图像从用户照片库发布到我的服务器.文件传输API似乎工作正常.我只是在我的服务器上检索这些信息感到困惑.
理想情况下,我需要做的是检索图像然后将其上传到我的服务器.但是,我似乎无法从文件传输中检索任何信息?
我的JavaScript代码(发布图像数据)是:
function onDeviceReady() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
function(message) { alert('get picture failed'); },
{ quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + …Run Code Online (Sandbox Code Playgroud) 我有一个多维数组,它由426个较小的数组组成,它们也包含4个属性.下面是426个数组之一的例子......
array( //Main array
0 => array( //1 of 426 arrays
'name' => 'Danny',
'email' => 'your@email.com',
'picture_url' => 'http://www.website.com',
'score' => 89
),
)
Run Code Online (Sandbox Code Playgroud)
我用jquery的ajax函数将这个数组发布到一个php文件,将它们添加到数据库中...我的问题是当它发布到php文件时,数组似乎被切断了.只有大约一半的数组实际到达php文件...
这让我相信在ajax上发布时可能存在文件大小限制.但是,我的阵列的大小似乎相对较小..
我在WAMP上运行我的应用程序..
任何人都可以解释可能发生的事情吗?
更新:
我像这样发布我的数组:
$.ajax({
type: "POST",
url: "invite_friends.php",
data: {
theID: me.id,
friends: multidimensional_array //This is the array <---
},
success: function(data, textStatus, jqXHR) {
return console.log(data);
},
error: function(jqXHR, textStatus, errorThrown) {
return alert("Error: Oops, there has been a problem");
}
});
Run Code Online (Sandbox Code Playgroud)
我像这样检索我的数组(在invite_friends.php中).
if($_POST['friends']) {
$friends = $_POST['friends'];
} else { …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题......
我有一堆像这样的陈述......
$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");
Run Code Online (Sandbox Code Playgroud)
然后是限制声明
$this->db->limit($limit, $offset);
Run Code Online (Sandbox Code Playgroud)
最后我得到了声明
$query = $this->db->get('table-name');
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要在我的限制语句之前计算结果,以获得没有限制的总行数.所以我尝试了这个..
$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");
$num_rows = $this->db->count_all_results();
$this->db->limit($limit, $offset);
$query = $this->db->get('table-name');
Run Code Online (Sandbox Code Playgroud)
这将使用where语句对我的行进行计数.但是,get语句现在获取没有先前where语句工作的记录.
它是不可见的,但有大量的代码处理更多的语句,并抓住网址中的东西,所以我宁愿不执行两次数据检索,以解决这个问题...
干杯!
好吧,想象一下,我正在用JavaScript创建一个口袋妖怪游戏.我有一个这样的对象......
pokemon = {
"pikachu": {hp: 100, probability: 0.1},
"squirtle": {hp: 90, probability: 0.2}
};
Run Code Online (Sandbox Code Playgroud)
我基本上需要一个函数来随机选择对象中的一个神奇宝贝,但也要基于概率.因此,在这种情况下,函数更可能选择"squirtle",因为它的概率高于"pikachu".
我正在使用Backbone和Slim PHP框架.我正在尝试将信息发布到我的API,但是Access-Control-Allow-Headers一直让我遇到问题......
我的控制台显示:
OPTIONS http://api.barholla.com/user/auth 405 (Method Not Allowed) zepto.min.js:2
XMLHttpRequest cannot load http://api.barholla.com/user/auth. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
Run Code Online (Sandbox Code Playgroud)
我的标题是:
Request URL:http://api.barholla.com/user/auth
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, content-type, accept
Access-Control-Request-Method:POST
Connection:keep-alive
Host:api.barholla.com
Origin:http://localhost
Referer:http://localhost/barholla/app/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
Response Headersview source
Access-Control-Allow-Origin:*
Allow:POST
Connection:close
Content-Type:application/json
Date:Thu, 08 Nov 2012 16:12:32 GMT
Server:Apache
Transfer-Encoding:chunked
X-Powered-By:Slim
X-Powered-By:PleskLin
Run Code Online (Sandbox Code Playgroud)
我的slim index.php文件中的标题是:
$res = …Run Code Online (Sandbox Code Playgroud) 在CodeIgniter中,我想在我的localhost(WAMP)上删除URL中的"index.php".例如,http://localhost.com/ci/index.php/controller/function到http://localhost.com/ci/controller/function
我改变了
$config['index_page'] = 'index.php'; to $config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)
我的.htaccess文件(位于根目录中,index.php所在的位置)如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /igniter
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or …Run Code Online (Sandbox Code Playgroud) Twitter的API以这种格式开出日期:
Thu, 18 Oct 2012 09:37:01 +0000
Run Code Online (Sandbox Code Playgroud)
对于我的数据库,是否可以使用PHP将其转换为日期时间格式?例如
2012-10-18 09:37:01
Run Code Online (Sandbox Code Playgroud) 我有一组具有不同属性的对象:
var arr = [];
var obj_1 = {
'key_a': 'value_a',
'key_b': 'value_b'
};
arr.push(obj_1);
var obj_2 = {
'key_a': 'value_a',
'key_b': 'value_b',
'key_c': 'value_c'
};
arr.push(obj_2);
Run Code Online (Sandbox Code Playgroud)
如果数组中的每个对象都不存在,我如何自动将新键(key_c)或任何其他键添加到数组中的每个对象?
所以数组看起来像这样:
[
{
'key_a': 'value_a'
'key_b': 'value_b'
'key_c': ''
},
{
'key_a': 'value_a'
'key_b': 'value_b'
'key_c': 'value_c'
}
]
Run Code Online (Sandbox Code Playgroud)
请注意:我正在构建一个Web scraper,未知的键/属性将添加到对象中并在foreach循环中推送到数组.
我正在使用Cordova 3.4.0,
当我尝试并运行时:
cordova emulate android
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
BUILD FAILED
/Users/danny/Documents/Development/adt-bundle-mac/sdk/tools/ant/build.xml:932: The following error occurred while executing this line:
/Users/danny/Documents/Development/adt-bundle-mac/sdk/tools/ant/build.xml:950: java.lang.ArrayIndexOutOfBoundsException: 1
at com.android.ant.DependencyGraph.parseDependencyFile(DependencyGraph.java:180)
at com.android.ant.DependencyGraph.<init>(DependencyGraph.java:54)
at com.android.ant.SingleDependencyTask.initDependencies(SingleDependencyTask.java:87)
at com.android.ant.AaptExecTask.execute(AaptExecTask.java:509)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at com.android.ant.IfElseTask.execute(IfElseTask.java:124)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown …Run Code Online (Sandbox Code Playgroud) 基本上我有一个位于服务器上的php脚本,它生成一个JSON文件,列出了mysql数据库中的位置.使用jQuery Mobile我正在开发一个应用程序来显示这些地方.我的代码适用于Chrome和Safari,但是当我将其移植到Phonegap时,它无效.我在互联网上搜索但找不到答案:(.
用于生成JSON(json.php)的php文件:
<?php
header('Content-type: application/json');
$server = "localhost";
$username = "xxx";
$password = "xxx";
$database = "xxx";
$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);
$sql = "SELECT * FROM places ORDER BY name ASC";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
$records = array();
while($row = mysql_fetch_assoc($result)) {
$records[] = $row;
}
mysql_close($con);
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
?>
Run Code Online (Sandbox Code Playgroud)
我的Javascript文件位于我的应用程序中(加载JSON并显示它):
$('#places').bind('pageinit', function(event) {
getPlaces();
}); …Run Code Online (Sandbox Code Playgroud) 我即将开展一个大型项目,在那里我将需要预定任务(cron作业)来运行一个脚本,该脚本将遍历我的整个实体数据库并每10分钟调用多个API,如Facebook,Twitter和Foursquare .我需要这个应用程序可扩展.
我已经可以预见到一些潜在的陷阱......
我的问题是如何构建我的应用程序......?
谢谢!
php ×7
javascript ×4
cordova ×3
arrays ×2
codeigniter ×2
slim ×2
ajax ×1
android ×1
ant ×1
api ×1
backbone.js ×1
cron ×1
cron-task ×1
cross-domain ×1
database ×1
date ×1
datetime ×1
file-upload ×1
header ×1
jquery ×1
json ×1
linux ×1
mod-rewrite ×1
probability ×1
random ×1
twitter ×1
utc ×1
wamp ×1
wampserver ×1