Moodle

No warning when new upload will overwrite an existing file

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.1
  • Fix Version/s: 2.0
  • Component/s: Resource
  • Labels:
    None
  • Environment:
    All
  • Affected Branches:
    MOODLE_11_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

It is generally considered good practice and user friendly for the application to warn the user when a file to be uploaded is identical in name with one already uploaded to the system. I uploaded a file (v. 1.1) and was not queried when I purposely uploaded a replacement file.

  1. file_exists.php
    04/Jul/08 8:33 PM
    0.3 kB
    Caio SBA
  2. index.php
    04/Jul/08 8:31 PM
    40 kB
    Caio SBA

Activity

Hide
Martin Dougiamas added a comment -

From Gustav Delius (gwd2 at york.ac.uk) Saturday, 8 May 2004, 09:21 PM:

I think this is quite an important annoyance but I have no good idea of what to do about it. Of course if we already had the new Moodle DMS with is version control ...

Show
Martin Dougiamas added a comment - From Gustav Delius (gwd2 at york.ac.uk) Saturday, 8 May 2004, 09:21 PM: I think this is quite an important annoyance but I have no good idea of what to do about it. Of course if we already had the new Moodle DMS with is version control ...
Hide
Caio SBA added a comment - - edited

Hi

I am a member of Moodle UFBA (Universidade Federal da Bahia - Brazil) team.
Here we had this problem.

I solved this for version 1.8 but I think this can fix the problem for other versions too.

The solution is simple... when trying to upload a file, an AJAX script makes a request to the server to check if the file exists or not. If true, a javascript confirm box asks the user if he wants to overwrite the file or not.

I don't know what exactly I must do to show this fix... by the time, the fix is shown below:

This javascript is added at files/index.php, just above the form printing:

<script type="text/javascript">
function file_exists(name) {
try { xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { /* do nothing */}
var long = name;
var broken = name.split("/");
var filename = broken.pop();
filename = filename.split(".");
var ext = filename.pop();
var just_name = filename.pop();
var id = '.$course->id.';
dest = "file_exists.php?id="id"&name="just_name"&ext="+ext;
xmlhttp.open("GET", dest, false);
xmlhttp.send(null);
if (xmlhttp.responseText==1) {
var overwrite = confirm(\'FIle \'just_name\'.\'ext\' already exists. Overwrite?\');
if (overwrite) { return true; } else { return false; }
} else { return true; }
}
</script>

At the form tag, we add: onsubmit=\"return file_exists(document.forms[0].userfile.value)\">

This is the PHP script called by the AJAX request to check if the file exists. Meaninfully, it is called file_exists.php and must be located at the folder files/ :

<?php
require_once("../config.php");
require_once("../lib/moodlelib.php");
$dir = $CFG->dataroot;
$name = $_GET['name'];
$name = clean_filename($name);
$id = $_GET['id'];
$ext = $_GET['ext'];
$file = $dir."/".$id."/".$name.".".$ext;
if (file_exists($file)) {
echo 1;
} else {
echo 0;
}
?>

I will check the way I must pass through to make this available (of course, if approved)

Show
Caio SBA added a comment - - edited Hi I am a member of Moodle UFBA (Universidade Federal da Bahia - Brazil) team. Here we had this problem. I solved this for version 1.8 but I think this can fix the problem for other versions too. The solution is simple... when trying to upload a file, an AJAX script makes a request to the server to check if the file exists or not. If true, a javascript confirm box asks the user if he wants to overwrite the file or not. I don't know what exactly I must do to show this fix... by the time, the fix is shown below: This javascript is added at files/index.php, just above the form printing: <script type="text/javascript"> function file_exists(name) { try { xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { /* do nothing */} var long = name; var broken = name.split("/"); var filename = broken.pop(); filename = filename.split("."); var ext = filename.pop(); var just_name = filename.pop(); var id = '.$course->id.'; dest = "file_exists.php?id="id"&name="just_name"&ext="+ext; xmlhttp.open("GET", dest, false); xmlhttp.send(null); if (xmlhttp.responseText==1) { var overwrite = confirm(\'FIle \'just_name\'.\'ext\' already exists. Overwrite?\'); if (overwrite) { return true; } else { return false; } } else { return true; } } </script> At the form tag, we add: onsubmit=\"return file_exists(document.forms[0].userfile.value)\"> This is the PHP script called by the AJAX request to check if the file exists. Meaninfully, it is called file_exists.php and must be located at the folder files/ : <?php require_once("../config.php"); require_once("../lib/moodlelib.php"); $dir = $CFG->dataroot; $name = $_GET['name']; $name = clean_filename($name); $id = $_GET['id']; $ext = $_GET['ext']; $file = $dir."/".$id."/".$name.".".$ext; if (file_exists($file)) { echo 1; } else { echo 0; } ?> I will check the way I must pass through to make this available (of course, if approved)
Hide
Caio SBA added a comment -

Can any one assign me to this issue?

Show
Caio SBA added a comment - Can any one assign me to this issue?
Hide
Caio SBA added a comment -

files/index.php modified to alert user when a same name file is being uploaded

Show
Caio SBA added a comment - files/index.php modified to alert user when a same name file is being uploaded
Hide
Caio SBA added a comment -

Simple PHP script which will be requested by Ajax.
This script checks if there is a file with the same name.

Show
Caio SBA added a comment - Simple PHP script which will be requested by Ajax. This script checks if there is a file with the same name.
Hide
Caio SBA added a comment -

The problem persists in 1.9.2

Show
Caio SBA added a comment - The problem persists in 1.9.2
Hide
Clark Shah-Nelson added a comment -

And it persists in 1.9.3 + - and currently, we are not even sure that overwriting a file is even possible - our current experiments are showing us that if we upload a file, make changes to the original, upload the newly changed file with same name - it will say it uploaded successfully but will not actually update the file - at least in the same browser!

1) I downloaded a DOC file - from a course

2) I made changes to the file -
3) I uploaded the new file, same name, and get the message that it uploaded successfully (without an overwrite message)
4) I download the same file, but see the older version

BUT - if I go to open in in another browser, (Seamonkey instead of Firefox) - the newer version downloads.

very strange.

Show
Clark Shah-Nelson added a comment - And it persists in 1.9.3 + - and currently, we are not even sure that overwriting a file is even possible - our current experiments are showing us that if we upload a file, make changes to the original, upload the newly changed file with same name - it will say it uploaded successfully but will not actually update the file - at least in the same browser! 1) I downloaded a DOC file - from a course 2) I made changes to the file - 3) I uploaded the new file, same name, and get the message that it uploaded successfully (without an overwrite message) 4) I download the same file, but see the older version BUT - if I go to open in in another browser, (Seamonkey instead of Firefox) - the newer version downloads. very strange.
Hide
Petr Škoda (skodak) added a comment -

For performance reasons course files are cached in browser - you need to use a different name or clear browser cache. This problem will be solved in 2.0.

Show
Petr Škoda (skodak) added a comment - For performance reasons course files are cached in browser - you need to use a different name or clear browser cache. This problem will be solved in 2.0.
Hide
Petr Škoda (skodak) added a comment -

Should be finally fixed in 2.0dev, please file new issues if necessary. Thank you for the report.

Petr Skoda

Show
Petr Škoda (skodak) added a comment - Should be finally fixed in 2.0dev, please file new issues if necessary. Thank you for the report. Petr Skoda

People

Vote (6)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: