Created
April 19, 2013 02:37
-
-
Save tlongren/5417718 to your computer and use it in GitHub Desktop.
Cross Site Ajax with Fine Uploader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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