mediaplugin用に仕様を合わせる必要がある。
ローカルに一度DLして一つずつアップロードするのは手間なので、どうやったら一気にできるか
考えてみた。
流れ
・http socket でフォームに送るデータを整形
・$_POST で受け取ったデータを $this->data に変換
・フォームに送る。
function uptest()
{
require_once 'HTTP/Request.php';
$url = "/tellers/upload/";
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader("Content-Type", "multi-part/form-data");
//foreign_key と アップしたいリモートファイルを指定
$req->addPostData("id",'1537');
$req->addFile("attach_file",WWW_ROOT.'files/image/1067.jpg');
$req->addPostData("_method", "POST");
$res = $req->sendRequest();
$res = $req->getResponseBody();
//IP判断でデバッグでなく、全てのユーザーが見れるようにデバッグ 2 にしておく。じゃないとデバッグが見れない。
pr($res);
$this->autoRender = false;
}
//データを整形してみる
function goal()
{
//pr($_POST);
//pr($_FILES);
$this->data['Teller']['id'] = $_POST['id'];
$this->data['Attachment'][0]['model'] = 'Teller';
$this->data['Attachment'][0]['group'] = '';
$this->data['Attachment'][0]['alternative'] = 'Teller';
$this->data['Attachment'][0]['file'] = $_FILES['attach_file'];
pr($this->data);
$this->autoRender = false;
}
function upload()
{
$this->set('title_for_layout','画像をアップロード');
//画像アップロードフォームの一番上にこれを追加。
if($_POST){
$this->data['Teller']['id'] = $_POST['id'];
$this->data['Attachment'][0]['model'] = 'Teller';
$this->data['Attachment'][0]['group'] = '';
$this->data['Attachment'][0]['alternative'] = 'Teller';
$this->data['Attachment'][0]['file'] = $_FILES['attach_file'];
}
if($this->data){
if(!empty($this->data['Attachment'][0]['file']['name'])){
if ($this->Teller->saveAll($this->data)) {
$this->redirect('/tellers/upload/');
echo '保存完了';
} else {
$this->Teller->invalidate('AttachmentError');
}
} else {
$this->Teller->invalidate('AttachmentError');
}
}
$res = $this->Teller->find('profile',array('conditions' => array('id' => t('id'))));
$this->set(
compact(
'res'
)
);
}
久しぶりにはまった。。。



