]> git.mjollnir.org Git - moodle.git/commitdiff
Changes to improve robustness of uploads, and make things compatible
authormoodler <moodler>
Sun, 5 Jan 2003 04:20:32 +0000 (04:20 +0000)
committermoodler <moodler>
Sun, 5 Jan 2003 04:20:32 +0000 (04:20 +0000)
with PHP 4.3.0.  Also some translation fixes with upload strings.

files/index.php
lang/en/moodle.php
mod/assignment/upload.php
mod/forum/lib.php
mod/forum/post.php

index cee36dd0c38654d9f4eae22729d2413eab190b71..9c2ddd973586c902b15634be1f42b1b9e00be089 100644 (file)
 
         case "upload":
             html_header($course, $wdir);
-            if ($save) {
-                if (!is_uploaded_file($userfile['tmp_name']) and $userfile['size'] > 0) {
-                    echo "<P>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));
                         }
                     }
                 }
                 $upload_max_filesize = get_max_upload_file_size();
                 $filesize = display_size($upload_max_filesize);
 
-                echo "<P>Upload a file (maximum size $filesize) into <B>$wdir</B>:";
+                $struploadafile = get_string("uploadafile");
+                $struploadthisfile = get_string("uploadthisfile");
+                $strmaxsize = get_string("maxsize", "", $filesize);
+                $strcancel = get_string("cancel");
+
+                echo "<P>$struploadafile ($strmaxsize) --> <B>$wdir</B>";
                 echo "<TABLE><TR><TD COLSPAN=2>";
                 echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"post\" ACTION=index.php>";
                 echo " <INPUT TYPE=hidden NAME=MAX_FILE_SIZE value=\"$upload_max_filesize\">";
                 echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
                 echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
                 echo " <INPUT TYPE=hidden NAME=action VALUE=upload>";
-                echo " <INPUT NAME=\"userfile\" TYPE=\"file\" size=\"50\">";
+                echo " <INPUT NAME=\"userfile\" TYPE=\"file\" size=\"60\">";
                 echo " </TD><TR><TD WIDTH=10>";
-                echo " <INPUT TYPE=submit NAME=save VALUE=\"Upload this file\">";
+                echo " <INPUT TYPE=submit NAME=save VALUE=\"$struploadthisfile\">";
                 echo "</FORM>";
                 echo "</TD><TD WIDTH=100%>";
                 echo "<FORM ACTION=index.php METHOD=get>";
                 echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
                 echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
                 echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
-                echo " <INPUT TYPE=submit VALUE=\"Cancel\">";
+                echo " <INPUT TYPE=submit VALUE=\"$strcancel\">";
                 echo "</FORM>";
                 echo "</TD></TR></TABLE>";
             }
index 17d3422359bb9ddc1cdfa39e4826eb919af673e4..34312d1b753b2f7504a54c58d3a06ebfbfae5e03 100644 (file)
@@ -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";
index 9b48d8e241cf939174003213249a8331bcbdd91b..6109ed23e2490132808ed0844c1c4647f6d8e684 100644 (file)
@@ -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");
         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 {
index 85bce17a319ecc09f27849ff493c9616da55e793..3006bc383f15e7fa092ded6ac55d58c6ce437d6c 100644 (file)
@@ -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 "";
     }
 
index 7109ed734aaebd676d758e55258cc9433048f917..cb108a63cb0f8a08b3d05e3d5824fbcc911214a7 100644 (file)
@@ -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"));