小编Gar*_*ett的帖子

PHP Curl File Upload发送Empty Upload

我正在尝试转换以下CURL:

curl -X POST \
  -H "Content-Type: image/jpeg" \
  --data-binary '@myPicture.jpg' \
  https://api.parse.com/1/files/pic.jpg
Run Code Online (Sandbox Code Playgroud)

到PHP:

$ch = curl_init();
$data = array('myPicture.jpg' => "@myPicture.jpg");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);

$headers = array();
$headers[] = "Content-Type: image/jpeg";
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt ($ch, CURLOPT_URL, 'https://api.parse.com/1/files/myPicture.jpg');

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_VERBOSE, true);

$response = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

但我的回答是false.这是我得到的print_r(curl_getinfo($ch), true):

Array
(
    [url] => https://api.parse.com/1/files/myPicture.jpg
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => …
Run Code Online (Sandbox Code Playgroud)

php upload curl

4
推荐指数
1
解决办法
5997
查看次数

RewriteEngine不在本地重写URL?

Options +FollowSymlinks

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteCond %{REQUEST_FILENAME} !-d # not a directory
RewriteRule ^(.+)$ index.php?params=$1 [L]
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我正试图转换任何类似的东西

mysite.com/x/y/z

mysite.com/index.php?params=x/y/z

但它没有用.我试过mysite.com/home并在index.php的第一行放了一个断点,但得到了404.

关于为什么这不适合我的任何想法?谢谢!

php apache .htaccess mod-rewrite

3
推荐指数
1
解决办法
192
查看次数

动态规划最小化平方和

我在练习考试中有这个问题,并且不知道如何解决它,所以我非常害怕决赛.无论如何,发现这个问题有一个答案将是缓解,并将帮助我理解动态编程,所以感谢阅读:)

问题:

给定n个数a1,...,a(正或负)的序列,我们希望将序列分成块,以便最小化块和的平方和,受每个块包含的约束的约束.至少2个,最多4个元素.换句话说,我们想找到1 = i [0] <i [1] <i [2] <... <i [k-1] <i [k] = n + 1来最小化(ai [0 ] + ... + ai [1] -1)^ 2 +(ai [1] + ... + ai [2] -1)^ 2 + ... +(ai [k-1] + .. .+ ai [k] -1)^ 2,这样2 <= i [1] - i [0] <= 4,2 <= i [2] - i [1] <= 4,..., 2 <= i [k] -i [k-1] <= 4.(注意,没有给出块数k.)提出O(n)时动态编程算法来解决问题.

我的问题:定义子问题.我唯一的线索是不断找到长度为4到2的最小总和,但是如果剩下1个怎么办呢?它是否加入现有的长度为2或3的组,或者是4组分组?更别说在O(n)中完成了......

algorithm complexity-theory dynamic-programming

3
推荐指数
1
解决办法
2089
查看次数

CakePHP:设置主页变量

将其添加到我display函数的末尾之后app/controllers/pages_controller.php

    // grab all message lists
    $this->loadModel('MessageList');
    $this->set('messageLists', $this->MessageList->find('all'));
Run Code Online (Sandbox Code Playgroud)

我尝试app/views/pages/home.ctp像这样访问它

<?php
        foreach($messageLists as $messageList) {
            print_r($messageList);
        }
    ?>
Run Code Online (Sandbox Code Playgroud)

但是我得到警告

Notice (8): Undefined variable: messageLists [APP\views\pages\home.ctp, line 9]
Run Code Online (Sandbox Code Playgroud)

app/config/routes.php有:

/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/views/pages/home.ctp)...
 */
    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); …
Run Code Online (Sandbox Code Playgroud)

controller routes cakephp cakephp-1.2

3
推荐指数
1
解决办法
2159
查看次数

CakePHP包含不与递归一起使用

当我尝试:

// Removed the limit to ensure that all of the group notes items can be found and collapsed
$recent_notes = $this->User->Note->find('all', array(
    'recursive' => 2,
    'order' => 'Note.created DESC',
    'conditions' => $conditions,
    'contains' => array(
        'NotesUser', 'Poster', 'Comment' => array('Poster')
    )
));
Run Code Online (Sandbox Code Playgroud)

它不会限制输出 - 我得到每个相关的模型.但是,当我没有指定recursive2,或者如果我指定为1,我错过了Comment=>Poster模型.

我怎样才能获得我需要的模型?谢谢!

cakephp model containable cakephp-1.2

3
推荐指数
1
解决办法
5446
查看次数

Ruby on Rails与Parse + Backbone.js

我去年开始制作我的应用程序,但最近有一个HOLY****时刻,我意识到用PHP开发一个严肃的Web应用程序,现在关于可扩展性和整体理智不会削减它.

这引出了以下选项:

  1. 用最美丽的MVC重写我的后端 - 37Signal的Ruby on Rails 或者
  2. 废弃我的数据库并在Backbone.js + Parse中重写我的后端

(Parse刚刚发布了他们的网络SDK)

我不是历史爱好者,但在这里听我说.PHP领导Web开发直到最近.现在Rails正在接管.仅这一点就可以让大多数人选择选项1.但是,如果Parse接管Rails就像Rails接管PHP一样?我正在为未来做准备,我开始认为Parse是未来的方式.

我应该如何重写我的应用程序,以便在未来几年内最大限度地提高可扩展性?

谢谢.

javascript parsing ruby-on-rails backbone.js

3
推荐指数
1
解决办法
2060
查看次数

为下一个实例化设置的骨干视图属性?

我有一个具有tooltip属性的视图.我想动态设置该属性initializerender.但是,当我设置它时,它会出现在该视图的下一个实例化而不是当前视图中:

    var WorkoutSectionSlide = Parse.View.extend( {      
        tag : 'div',
        className : 'sectionPreview',
        attributes : {},

        template : _.template(workoutSectionPreviewElement),

        initialize : function() {
//          this.setDetailsTooltip(); // doesn't work if run here either
        },

        setDetailsTooltip : function() {
            // build details
            ...

            // set tooltip
            this.attributes['tooltip'] = details.join(', ');
        },

        render: function() {            
            this.setDetailsTooltip(); // applies to next WorkoutViewSlide

            // build firstExercises images
            var firstExercisesHTML = '';
            for(key in this.model.workoutExerciseList.models) {
                // stop after 3
                if(key …
Run Code Online (Sandbox Code Playgroud)

javascript backbone.js backbone-views

3
推荐指数
2
解决办法
4464
查看次数

在@implementation中使用'self'

我试图播放语音音频之上iPodMusicPlayer通过使TriggerIO本地插件,不过我无法访问self对象.

#import "alert_API.h"

@implementation alert_API

+ (void)play:(ForgeTask*)task text:(NSString *)filename {
    NSURL* url = [[NSBundle mainBundle] URLForResource:@"Rondo_Alla_Turka_Short" withExtension:@"aiff"];
    NSAssert(url, @"URL is valid.");
    NSError* error = nil;


    /* ERROR: /Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/alert_API.m:45:13: Member reference type 'struct objc_class *' is a pointer; maybe you meant to use '->'? */
    self->player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

    /* ERROR: /Users/gsquare567/forge-workspace/plugins/audio/inspector/ios-inspector/ForgeModule/alert/alert_API.m:45:13: Incomplete definition of type 'struct objc_class' */
    if(!self.player)
    {
        NSLog(@"Error creating player: %@", error);
    }


    [task success:nil];
}

@end
Run Code Online (Sandbox Code Playgroud)

该属性定义alert_API.h …

objective-c ios trigger.io

3
推荐指数
1
解决办法
2111
查看次数

Trigger.IO:知道何时通过推送通知打开应用程序

有没有办法知道什么时候通过推送通知打开应用程序?这对于将用户重定向到应用程序中针对该推送通知的相关位置将是有用的.

push-notification trigger.io

3
推荐指数
1
解决办法
208
查看次数

在Koa发送响应后运行代码

为了优化响应延迟,必须将响应发送回客户端之后执行工作.但是,在发送响应之后,我似乎能够获得运行代码的唯一方法是使用setTimeout.有没有更好的办法?也许某个地方在发送响应后插入代码,或者某处异步运行代码?

这是一些代码.

koa                  = require 'koa'
router               = require 'koa-router'

app = koa()

# routing
app.use router app

app
  .get '/mypath', (next) ->
    # ...
    console.log 'Sending response'

    yield next

    # send response???

    console.log 'Do some more work that the response shouldn\'t wait for'
Run Code Online (Sandbox Code Playgroud)

javascript optimization generator ecmascript-6 koa

3
推荐指数
1
解决办法
3816
查看次数