Issue Details (XML | Word | Printable)

Key: MDL-805
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Petr Skoda
Reporter: Tom Robb
Votes: 4
Watchers: 4
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

No warning when new upload will overwrite an existing file

Created: 29/Sep/03 01:12 PM   Updated: 10/Feb/09 06:15 AM
Return to search
Component/s: Resource
Affects Version/s: 1.1
Fix Version/s: None

File Attachments: 1. File file_exists.php (0.3 kB)
2. File index.php (40 kB)

Environment: All

Participants: Caio SBA, Clark Shah-Nelson, Martin Dougiamas, Petr Skoda and Tom Robb
Security Level: None
Affected Branches: MOODLE_11_STABLE


 Description  « Hide
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.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Martin Dougiamas added a comment - 08/May/04 09:21 PM
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 ...


Caio SBA added a comment - 14/Nov/07 09:22 PM - 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)


Caio SBA added a comment - 04/Jul/08 08:26 PM
Can any one assign me to this issue?

Caio SBA added a comment - 04/Jul/08 08:31 PM
files/index.php modified to alert user when a same name file is being uploaded

Caio SBA added a comment - 04/Jul/08 08:33 PM
Simple PHP script which will be requested by Ajax.
This script checks if there is a file with the same name.

Caio SBA added a comment - 28/Aug/08 04:42 AM
The problem persists in 1.9.2

Clark Shah-Nelson added a comment - 10/Feb/09 06:02 AM
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.


Petr Skoda added a comment - 10/Feb/09 06:15 AM
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.