From 2850bfb915fa5dc28d290910cba1c97b0c7e3b50 Mon Sep 17 00:00:00 2001 From: Russell McLoughlin Date: Wed, 1 Jun 2011 11:25:31 -0700 Subject: Modified upload code so that it uses php's built in file copy function rather than reading the entire uploaded file into memory from the temporary upload directory and then saving it to elgg's data dir. --- mod/file/actions/file/upload.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'mod/file/actions') diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index e04203f67..fe93661f2 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -106,9 +106,7 @@ if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $file->originalfilename = $_FILES['upload']['name']; $file->simpletype = file_get_simple_type($_FILES['upload']['type']); - $file->open("write"); - $file->write(get_uploaded_file('upload')); - $file->close(); + move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore()); $guid = $file->save(); -- cgit v1.2.3 From 5ce0b61f361809949f88fcd6566eebc3abb2c8df Mon Sep 17 00:00:00 2001 From: Russell McLoughlin Date: Wed, 1 Jun 2011 13:16:39 -0700 Subject: Modified upload script to guarentee that the directory under elgg data is created or exists. Removed strange chunking code with builtin php function --- mod/file/actions/file/upload.php | 3 +++ mod/file/download.php | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'mod/file/actions') diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index fe93661f2..9581698be 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -106,6 +106,9 @@ if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $file->originalfilename = $_FILES['upload']['name']; $file->simpletype = file_get_simple_type($_FILES['upload']['type']); + // Open the file to guarentee the directory exists + $file->open("write"); + $file->close(); move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore()); $guid = $file->save(); diff --git a/mod/file/download.php b/mod/file/download.php index a386d490f..8e0287a1e 100644 --- a/mod/file/download.php +++ b/mod/file/download.php @@ -33,8 +33,7 @@ if (strpos($mime, "image/") !== false) { header("Content-Disposition: attachment; filename=\"$filename\""); } -$contents = $file->grabFile(); -$splitString = str_split($contents, 8192); -foreach ($splitString as $chunk) { - echo $chunk; -} +ob_clean(); +flush(); +readfile($file->getFilenameOnFilestore()); +exit; -- cgit v1.2.3 From d9485cb8e8982c668d7aa374f80ad2fa4c93753d Mon Sep 17 00:00:00 2001 From: Russell McLoughlin Date: Thu, 2 Jun 2011 15:54:16 -0700 Subject: fixed embarrassing spelling mistake. --- mod/file/actions/file/upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/file/actions') diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index 9581698be..518d59891 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -106,7 +106,7 @@ if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $file->originalfilename = $_FILES['upload']['name']; $file->simpletype = file_get_simple_type($_FILES['upload']['type']); - // Open the file to guarentee the directory exists + // Open the file to guarantee the directory exists $file->open("write"); $file->close(); move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore()); -- cgit v1.2.3 From 0afdb10ff1d079e623685a91c59bac4802aa0069 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 19 Jun 2011 15:02:57 -0400 Subject: removed the special ajax/embed code from the file plugin --- mod/file/actions/file/upload.php | 53 ++++++---------------------- mod/file/views/default/file/embed_upload.php | 8 ----- mod/file/views/default/forms/file/upload.php | 6 ---- 3 files changed, 10 insertions(+), 57 deletions(-) delete mode 100644 mod/file/views/default/file/embed_upload.php (limited to 'mod/file/actions') diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index 5d5c28bee..b17fb6298 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -13,8 +13,6 @@ $container_guid = (int) get_input('container_guid', 0); $guid = (int) get_input('file_guid'); $tags = get_input("tags"); -$ajax = get_input('ajax', FALSE); - if ($container_guid == 0) { $container_guid = elgg_get_logged_in_user_guid(); } @@ -33,17 +31,8 @@ if ($new_file) { if (empty($_FILES['upload']['name'])) { $error = elgg_echo('file:nofile'); - - if ($ajax) { - echo json_encode(array( - 'status' => 'error', - 'message' => $error - )); - exit; - } else { - register_error($error); - forward(REFERER); - } + register_error($error); + forward(REFERER); } $file = new FilePluginFile(); @@ -158,44 +147,22 @@ elgg_clear_sticky_form('file'); // handle results differently for new files and file updates -// ajax is only for new files from embed right now. if ($new_file) { if ($guid) { $message = elgg_echo("file:saved"); - if ($ajax) { - echo json_encode(array( - 'status' => 'success', - 'message' => $message - )); - exit; - - } else { - system_message($message); - add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $file->guid); - } + system_message($message); + add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $file->guid); } else { // failed to save file object - nothing we can do about this $error = elgg_echo("file:uploadfailed"); - - if ($ajax) { - echo json_encode(array( - 'status' => 'error', - 'message' => $error - )); - exit; - - } else { - register_error($error); - } + register_error($error); } - if (!$ajax) { - $container = get_entity($container_guid); - if (elgg_instanceof($container, 'group')) { - forward("file/group/$container->guid/all"); - } else { - forward("file/owner/$container->username"); - } + $container = get_entity($container_guid); + if (elgg_instanceof($container, 'group')) { + forward("file/group/$container->guid/all"); + } else { + forward("file/owner/$container->username"); } } else { diff --git a/mod/file/views/default/file/embed_upload.php b/mod/file/views/default/file/embed_upload.php deleted file mode 100644 index e5076b052..000000000 --- a/mod/file/views/default/file/embed_upload.php +++ /dev/null @@ -1,8 +0,0 @@ - 'file_embed_upload'), array('ajax' => TRUE)); - - diff --git a/mod/file/views/default/forms/file/upload.php b/mod/file/views/default/forms/file/upload.php index aadc449fd..da764c3d8 100644 --- a/mod/file/views/default/forms/file/upload.php +++ b/mod/file/views/default/forms/file/upload.php @@ -15,7 +15,6 @@ if (!$container_guid) { $container_guid = elgg_get_logged_in_user_guid(); } $guid = elgg_extract('guid', $vars, null); -$ajax = elgg_extract('ajax', $vars, FALSE); if ($guid) { $file_label = elgg_echo("file:replace"); @@ -57,11 +56,6 @@ if ($categories) { echo elgg_view('input/hidden', array('name' => 'container_guid', 'value' => $container_guid)); -//@todo this should not be necessary in 1.8... -- ajax actions can be auto-detected -if ($ajax) { - echo elgg_view('input/hidden', array('name' => 'ajax', 'value' => 1)); -} - if ($guid) { echo elgg_view('input/hidden', array('name' => 'file_guid', 'value' => $guid)); } -- cgit v1.2.3