Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cross Site Ajax with Fine Uploader
function createUploader() {
var uploader = new qq.FineUploader({
element: document.getElementById('bootstrapped-fine-uploader'),
debug: false,
request: {
endpoint: 'http://sub.domain.com/upload.php',
paramsInBody: false,
params: {
folder: '<?=$folder?>',
mirror: "<?=$_SESSION['u_name']?>"
}
},
cors: {
expected: true,
},
validation: {
allowedExtensions: ['zip', 'png', 'jpg', 'txt', 'img', 'jpeg', 'rar', 'tar', 'gz', 'exe','xz','apk'],
sizeLimit: 524288000 // 500 MB
},
text: {
uploadButton: '<div><i class="icon-hdd icon-white"></i>&nbsp;Select Files</div>'
},
template: '<div class="qq-uploader">' +
'<pre class="qq-upload-drop-area"><span>{dragZoneText}</span></pre>' +
'<div class="qq-upload-button btn btn-primary" style="width: 140px;">{uploadButtonText}</div>' +
'<span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>' +
'<ul class="qq-upload-list" style="margin-top: 10px; text-align: center;"></ul>' +
'</div>',
classes: {
success: 'alert alert-info',
fail: 'alert alert-error'
}
});
}
window.onload = createUploader;
<?php
header('Access-Control-Allow-Origin: http://www.longren.org');
header('Access-Control-Allow-Headers: cache-control, x-requested-with, content-type, origin');
$uploadPrefix = "/home/tyler/";
$file = $_FILES['qqfile'];
$mirror = $_GET['mirror'];
$folder = $_GET['folder'];
if ($folder == "main") {
$uploadDirectory = $uploadPrefix.$mirror;
} else {
$uploadDirectory = $uploadPrefix.$mirror.DIRECTORY_SEPARATOR.$folder;
}
$target = $uploadDirectory.DIRECTORY_SEPARATOR.$file['name'];
$result = null;
if (move_uploaded_file($file['tmp_name'], $target)){
$result = array('success'=> true);
$result['uploadName'] = $file['name'];
} else {
$result = array('error'=> "Upload failed");
}
header("Content-Type: text/plain");
echo json_encode($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment