From: moodler Date: Sun, 5 Jan 2003 04:20:32 +0000 (+0000) Subject: Changes to improve robustness of uploads, and make things compatible X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3b7c1de95eea15feb495d1212ac8face80af4c0e;p=moodle.git Changes to improve robustness of uploads, and make things compatible with PHP 4.3.0. Also some translation fixes with upload strings. --- diff --git a/files/index.php b/files/index.php index cee36dd0c3..9c2ddd9735 100644 --- a/files/index.php +++ b/files/index.php @@ -92,18 +92,25 @@ case "upload": html_header($course, $wdir); - if ($save) { - if (!is_uploaded_file($userfile['tmp_name']) and $userfile['size'] > 0) { - echo "

Error: That was not a valid file."; + if (!empty($_FILES['userfile'])) { + $userfile = $_FILES['userfile']; + } else { + $save = false; + } + if (!empty($save)) { + if (!is_uploaded_file($userfile['tmp_name']) or $userfile['size'] == 0) { + notify(get_string("uploadnofilefound")); } else { $userfile_name = clean_filename($userfile['name']); if ($userfile_name) { $newfile = "$basedir$wdir/$userfile_name"; if (move_uploaded_file($userfile['tmp_name'], $newfile)) { - echo "Uploaded $userfile_name (".$userfile['type'].") to $wdir"; + $a = NULL; + $a->file = "$userfile_name (".$userfile['type'].")"; + $a->directory = $wdir; + print_string("uploadedfileto", "", $a); } else { - echo "A problem occurred while uploading '$userfile_name'"; - echo " (possibly it was too large)"; + notify(get_string("uploadproblem", "", $userfile_name)); } } } @@ -113,23 +120,28 @@ $upload_max_filesize = get_max_upload_file_size(); $filesize = display_size($upload_max_filesize); - echo "

Upload a file (maximum size $filesize) into $wdir:"; + $struploadafile = get_string("uploadafile"); + $struploadthisfile = get_string("uploadthisfile"); + $strmaxsize = get_string("maxsize", "", $filesize); + $strcancel = get_string("cancel"); + + echo "

$struploadafile ($strmaxsize) --> $wdir"; echo "
"; echo "
"; echo " "; echo " "; echo " "; echo " "; - echo " "; + echo " "; echo "
"; - echo " "; + echo " "; echo ""; echo ""; echo "
"; echo " "; echo " "; echo " "; - echo " "; + echo " "; echo "
"; echo "
"; } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 17d3422359..34312d1b75 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -496,6 +496,9 @@ $string['updatingain'] = "Updating a \$a->what in \$a->in"; $string['updatethis'] = "Update this \$a"; $string['upload'] = "Upload"; $string['uploadafile'] = "Upload a file"; +$string['uploadedfileto'] = "Uploaded \$a->file to \$a->directory"; +$string['uploadnofilefound'] = "No file was found - are you sure you selected one to upload?"; +$string['uploadproblem'] = "An unknown problem occurred while uploading the file '\$a' (perhaps it was too large?)"; $string['uploadthisfile'] = "Upload this file"; $string['userdeleted'] = "This user account has been deleted"; $string['userdescription'] = "Description"; diff --git a/mod/assignment/upload.php b/mod/assignment/upload.php index 9b48d8e241..6109ed23e2 100644 --- a/mod/assignment/upload.php +++ b/mod/assignment/upload.php @@ -5,7 +5,9 @@ require_variable($id); // Assignment ID - $newfile = $HTTP_POST_FILES["newfile"]; + if (!empty($_FILES['newfile'])) { + $newfile = $_FILES['newfile']; + } if (! $assignment = get_record("assignment", "id", $id)) { error("Not a valid assignment ID"); @@ -41,7 +43,10 @@ error("Sorry, an error in the system prevents you from uploading files: contact your teacher or system administrator"); } - if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) { + if (empty($newfile)) { + notify(get_string("uploadnofilefound", "assignment") ); + + } else if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) { if ($newfile['size'] > $assignment->maxbytes) { notify(get_string("uploadfiletoobig", "assignment", $assignment->maxbytes)); } else { diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 85bce17a31..3006bc383f 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1159,10 +1159,10 @@ function forum_print_attachments($post, $return=NULL) { function forum_add_attachment($post, $newfile) { // $post is a full post record, including course and forum -// $newfile is a full upload array from HTTP_POST_FILES +// $newfile is a full upload array from $_FILES // If successful, this function returns the name of the file - if (!isset($newfile['name'])) { + if (empty($newfile['name'])) { return ""; } diff --git a/mod/forum/post.php b/mod/forum/post.php index 7109ed734a..cb108a63cb 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -15,7 +15,7 @@ $post->subject = strip_tags($post->subject); // Strip all tags $post->message = clean_text($post->message, $post->format); // Clean up any bad tags - $post->attachment = $HTTP_POST_FILES["attachment"]; + $post->attachment = $_FILES["attachment"]; if (!$post->subject and !$post->message) { error(get_string("emptymessage", "forum"));