PDA

View Full Version : Reponse blank from server which located in another domain.



arpeggian
19 May 2013, 7:21 AM
I need to upload file on cross doamin server. File is getting uploaded successfully using extjs form.
But,I am not able to get response.
Please let me know the solution.

this is my client code:


form.submit({
url: 'Another domain',
waitMsg: 'Mengupload file...',
method: 'POST',
useDefaultXhrHeader: false,
//withCredentials: true,
params: {
user_id: '<?php echo $_SESSION["username"]?>',
},
//timeout: 0 ,
success: function(fp, o) {
console.log(o);
var data = o.result;

Ext.Msg.alert('Informasi', data.msg, function(){
var xsearch = uploadFotoIdpelSearchPanel.getComponent('search');
xsearch.fireEvent('click', xsearch);
});
},
failure: function(fp, o) {
console.log(o.result);
Ext.Msg.alert('Informasi', o.result.msg);
}

});

and this is my server code:


<?php
session_start();
ini_set('max_execution_time','-1');
require_once('../config.php');


$idpel = $_POST['idpel'];
$tahun = $_POST['tahun'];
$bulan = $_POST['bulan'];
$foto_path = $_POST['foto_path'];
$blth = $tahun.str_pad($bulan, 2, "0", STR_PAD_LEFT);
$user_id = strtoupper($_POST['user_id']);
$temp_file_name = $_FILES['file_foto']['tmp_name'];
$original_file_name = $_FILES['file_foto']['name'];
// Find file extention
$ext = explode ('.', $original_file_name);
$ext = $ext [count ($ext) - 1];
$ext = strtoupper($ext);


$mime_type = array("JPG", "JPEG", "PNG");


.........any code goes here.......


if(in_array($ext, $mime_type)){

unlink('D:Photo/'.$foto_path);

$file_path = 'D:/Photo/'.$unitup.'/'.$blth.'/';
$file_name = $idpel.'.'.strtolower($ext);
if (!is_dir($file_path)) {
mkdir($file_path,0777,true);
}


move_uploaded_file ($temp_file_name, $file_path.$file_name);

$beres = false;
$time_limit = 1200;
while( !$beres && $i <= $time_limit){
sleep(1);
$i++;
if(file_exists($file_path.$file_name)){
$beres = true;
}
}

if($beres){
$response['success'] = true;
$response['msg'] = 'File Foto berhasil diupload';




}
else{
$response['success'] = false;
$response['msg'] = 'Waktu selama '.$time_limit.' detik untuk proses upload foto ke Database telah habis';
}


}
else{
$response['success'] = false;
$response['msg'] = 'File yang bisa diupload adalah file '.implode(",", $mime_type);
}


header('Access-Control-Allow-Origin: http://www.mydomain.com');
header('Access-Control-Allow-Methods: PROPFIND, PROPPATCH, COPY, MOVE, DELETE, MKCOL, LOCK, UNLOCK, PUT, GETLIB, VERSION-CONTROL, CHECKIN, CHECKOUT, UNCHECKOUT, REPORT, UPDATE, CANCELUPLOAD, HEAD, OPTIONS, GET, POST');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: X-PINGOTHER, Overwrite, Destination, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control');
header('Access-Control-Allow-Credentials : true');


$response['test'] = 'test';


echo json_encode($response);


?>

arpeggian
20 May 2013, 11:28 PM
anyone, please