X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=addon%2Fjs_upload%2Fjs_upload.php;h=331548f8803258d2a221397a2be7165a754d0838;hb=40092c83a5568a9896c05f7ccdd8da4649f5271a;hp=b738ade241d1400628737ea9309c2edd9df1f28a;hpb=076c25e1034f35e486bf5a38c186ab897de4e3b6;p=friendica.git
diff --git a/addon/js_upload/js_upload.php b/addon/js_upload/js_upload.php
index b738ade241..331548f880 100644
--- a/addon/js_upload/js_upload.php
+++ b/addon/js_upload/js_upload.php
@@ -1,5 +1,12 @@
+ */
+
/**
*
* JavaScript Photo/Image Uploader
@@ -7,9 +14,6 @@
* Uses Valum 'qq' Uploader.
* Module Author: Chris Case
*
- * Prior to enabling, ensure that you have a directory 'uploads'
- * which is writable by the web server.
- *
*/
@@ -36,6 +40,11 @@ function js_upload_form(&$a,&$b) {
$b['addon_text'] .= '';
$b['addon_text'] .= '';
+ $upload_msg = t('Upload a file');
+ $drop_msg = t('Drop files here to upload');
+ $cancel = t('Cancel');
+ $failed = t('Failed');
+
$b['addon_text'] .= <<< EOT
@@ -65,17 +74,43 @@ function createUploader() {
uploader = new qq.FileUploader({
element: document.getElementById('file-uploader-demo1'),
action: '{$b['post_url']}',
+
+ template: '
' +
+ '
$drop_msg
' +
+ '
$upload_msg
' +
+ '
' +
+ '
',
+
+ // template for one item in file list
+ fileTemplate: '
' +
+ '' +
+ '' +
+ '' +
+ '$cancel' +
+ '$failed' +
+ '',
+
debug: true,
onSubmit: function(id,filename) {
-
- uploader.setParams( {
- newalbum : document.getElementById('photos-upload-newalbum').value,
- album : document.getElementById('photos-upload-album-select').value,
- group_allow : getSelected(document.getElementById('group_allow')).join(','),
- contact_allow : getSelected(document.getElementById('contact_allow')).join(','),
- group_deny : getSelected(document.getElementById('group_deny')).join(','),
- contact_deny : getSelected(document.getElementById('contact_deny')).join(',')
- });
+ if (typeof acl!="undefined"){
+ uploader.setParams( {
+ newalbum : document.getElementById('photos-upload-newalbum').value,
+ album : document.getElementById('photos-upload-album-select').value,
+ group_allow : acl.allow_gid.join(','),
+ contact_allow : acl.allow_cid.join(','),
+ group_deny : acl.deny_gid.join(','),
+ contact_deny : acl.deny_cid.join(',')
+ });
+ } else {
+ uploader.setParams( {
+ newalbum : document.getElementById('photos-upload-newalbum').value,
+ album : document.getElementById('photos-upload-album-select').value,
+ group_allow : getSelected(document.getElementById('group_allow')).join(','),
+ contact_allow : getSelected(document.getElementById('contact_allow')).join(','),
+ group_deny : getSelected(document.getElementById('group_deny')).join(','),
+ contact_deny : getSelected(document.getElementById('contact_deny')).join(',')
+ });
+ }
}
});
}
@@ -101,11 +136,11 @@ function js_upload_post_init(&$a,&$b) {
// max file size in bytes
- $sizeLimit = 6 * 1024 * 1024;
+ $sizeLimit = get_config('system','maximagesize'); //6 * 1024 * 1024;
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
- $result = $uploader->handleUpload('uploads/');
+ $result = $uploader->handleUpload();
// to pass data through iframe you will need to encode all html tags
@@ -113,6 +148,7 @@ function js_upload_post_init(&$a,&$b) {
if(isset($result['error'])) {
logger('mod/photos.php: photos_post(): error uploading photo: ' . $result['error'] , 'LOGGER_DEBUG');
+ echo json_encode($result);
killme();
}
@@ -124,11 +160,10 @@ function js_upload_post_file(&$a,&$b) {
$result = $a->data['upload_result'];
- $b['src'] = 'uploads/' . $result['filename'];
+ $b['src'] = $result['path'];
$b['filename'] = $result['filename'];
$b['filesize'] = filesize($b['src']);
-logger('post_file' . print_r($b, true));
}
@@ -147,28 +182,32 @@ logger('upload_post_end');
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
+
+ private $pathnm = '';
+
/**
- * Save the file to the specified path
+ * Save the file in the temp dir.
* @return boolean TRUE on success
*/
- function save($path) {
+ function save() {
$input = fopen("php://input", "r");
- $temp = tmpfile();
+ $this->pathnm = tempnam(sys_get_temp_dir(),'frn');
+ $temp = fopen($this->pathnm,"w");
$realSize = stream_copy_to_stream($input, $temp);
+
fclose($input);
+ fclose($temp);
if ($realSize != $this->getSize()){
return false;
}
-
- $target = fopen($path, "w");
- fseek($temp, 0, SEEK_SET);
- stream_copy_to_stream($temp, $target);
- fclose($target);
-
return true;
}
+ function getPath() {
+ return $this->pathnm;
+ }
+
function getName() {
return $_GET['qqfile'];
}
@@ -187,16 +226,22 @@ class qqUploadedFileXhr {
*/
class qqUploadedFileForm {
+
+
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
- function save($path) {
- if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){
- return false;
- }
+
+
+ function save() {
return true;
}
+
+ function getPath() {
+ return $_FILES['qqfile']['tmp_name'];
+ }
+
function getName() {
return $_FILES['qqfile']['name'];
}
@@ -216,8 +261,6 @@ class qqFileUploader {
$this->allowedExtensions = $allowedExtensions;
$this->sizeLimit = $sizeLimit;
- $this->checkServerSettings();
-
if (isset($_GET['qqfile'])) {
$this->file = new qqUploadedFileXhr();
} elseif (isset($_FILES['qqfile'])) {
@@ -225,17 +268,9 @@ class qqFileUploader {
} else {
$this->file = false;
}
+
}
- private function checkServerSettings(){
- $postSize = $this->toBytes(ini_get('post_max_size'));
- $uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
- logger('mod/photos.php: qqFileUploader(): upload_max_filesize=' . $uploadSize , 'LOGGER_DEBUG');
- if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit){
- $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
- die("{'error':'increase post_max_size and upload_max_filesize to $size'}");
- }
- }
private function toBytes($str){
$val = trim($str);
@@ -251,10 +286,7 @@ class qqFileUploader {
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
- function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
- if (!is_writable($uploadDirectory)){
- return array('error' => t('Server error. Upload directory isn\'t writable.'));
- }
+ function handleUpload(){
if (!$this->file){
return array('error' => t('No files were uploaded.'));
@@ -289,18 +321,18 @@ class qqFileUploader {
return array('error' => t('File has an invalid extension, it should be one of ') . $these . '.');
}
- if(!$replaceOldFile){
- /// don't overwrite previous files that were uploaded
- while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
- $filename .= rand(10, 99);
- }
- }
-
- if ($this->file->save($uploadDirectory . $filename . '.' . $ext)){
- return array('success'=>true,'filename' => $filename . '.' . $ext);
+ if ($this->file->save()){
+ return array(
+ 'success'=>true,
+ 'path' => $this->file->getPath(),
+ 'filename' => $filename . '.' . $ext
+ );
} else {
- return array('error'=> t('Could not save uploaded file.') .
- t('The upload was cancelled, or server error encountered'),'filename' => $filename . '.' . $ext);
+ return array(
+ 'error'=> t('Upload was cancelled, or server error encountered'),
+ 'path' => $this->file->getPath(),
+ 'filename' => $filename . '.' . $ext
+ );
}
}