Suggestion and solution for Wiki Upload image beahviour
Hi,
first i like tikiwiki. But we noticed there is some strange behaviour in the possibility to upload directly images to a wikipage (not the image gallery) while you edit this page: Upload an image with an name already existing just overwrites the original image, without any checkings. So if 2 people on differents pages are using an image like "screenshot.jpg" they disturb each other.
We discussed this problem and now have a suggestion to make life easier for users. Here comes the idea and the needed code.
There are 3 possible cases:
- CASE: you are editing page "A" and want to upload image A.jpg. A.jpg doesn't exists on any page in this wiki-domain, so we just act like before. Uploading image to wik_up/$tikiDomain/A.jpg and adding tag at bottom of page.
- CASE: you are editing page "A" and try to upload A.jpg, but A.jpg already exists and is already linked from "A". So we guess the user want to upload a new version of A.jpg. We update A.jpg in wiki_up and dont't add the tag to bottom of page, couse the picture-tag is already there.
- CASE: you are editing page "A" and try to upload B.jpg, but B.jpg already exist in wiki_up/$tikidomain (e.g. in this wiki) and is linked from an other page. So we guess the user does not know this and want to upload a new image. So we find a new name for his file, saving his image with the new name in wiki_up/$domainname and and the picture tag at bottom of page with the new filename.
Hope this idea to handle the image uploads is useable for other too. Below follows the code. To get it to work you have to insert this code into tiki-editpage.php (in tiki-root-dir) instead of the old "Upload pictures here" code (look for the comment in the code).
CODE
// Upload pictures here if (($feature_wiki_pictures == 'y') && (isset($tiki_p_upload_picture)) && ($tiki_p_upload_picture == 'y')) { if (isset($_FILES['picfile1']) && is_uploaded_file($_FILES['picfile1']['tmp_name'])) { $picname = $_FILES['picfile1']['name']; // if filename not exists behave like before, if not: // if filename exists already on other page create new filename filename_xxx.extension with xxx is a number // if filename exists already on this page just overwrite the file with the new version and dont create a tag on bottom of page if ( is_file("img/wiki_up/$tikidomain" . $picname) ) { //file already there //test if filename exists as picture link in pagesourcecode if (substr_count( $_REQUEST["edit"],"{picture file=img/wiki_up/$tikidomain" . $picname ."}" )>0) { //file already used by this page, just change it move_uploaded_file($_FILES['picfile1']['tmp_name'], "img/wiki_up/$tikidomain" . $picname); } else { //file already in other page, create new name $tmp_counter = 1; do { $new_picname = $tmp_counter ."_".$picname; $tmp_counter++; } while ( is_file("img/wiki_up/$tikidomain". $new_picname) ); move_uploaded_file($_FILES['picfile1']['tmp_name'], "img/wiki_up/$tikidomain" . $new_picname); $_REQUEST["edit"] = $_REQUEST["edit"] . "{picture file=img/wiki_up/$tikidomain$new_picname}"; } } else { //new file move_uploaded_file($_FILES['picfile1']['tmp_name'], "img/wiki_up/$tikidomain" . $picname); $_REQUEST["edit"] = $_REQUEST["edit"] . "{picture file=img/wiki_up/$tikidomain$picname}"; } } }
Greetings
Andreas