1 (edited by Loiso 2005-02-26 02:37)

Topic: UploadMoD

##        Mod title:  UploadMoD
##
##      Mod version:  1.0
##   Works on PunBB:  1.2.1
##     Release date:  2005-02-23
##           Author:  Yevgen Zinchenko aka Loiso (loiso@ukrtop.com)
##
##      Description:  Mod allows to site users upload their files to the
##                    site. Also Mod has simple permission system for upload 
##                    managing. AM plugin is included in this release to  
##                    set permissions for usergroups.
##
##   Affected files:  none
##
##       Affects DB:  Yes
##
##            Notes:  This mod was originally based on punUpload 1.1.1 by 
##                    ultime (Pierre-Luc Lacroix - ultime@omgultime.com).  
##                                         
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

Download here

Sorry, there is no demo for this module so far. However, here is some screenshots:

User section:

http://www.utopia-ru.net/pun/user.gif

Administration:

http://www.utopia-ru.net/pun/admin1.gif

http://www.utopia-ru.net/pun/admin2.gif

Re: UploadMoD

very nice

3 (edited by Ataxy 2005-02-26 03:57)

Re: UploadMoD

what is there to change to make it work with 1.2.2 since its made for 1.2.1
ok found it just mod the installer script to accept v1.2.2

4 (edited by Ataxy 2005-02-26 04:05)

Re: UploadMoD

ok i got it iinstalled but now how do one upload when you do your post there is no attachement option or anything
basicly where should i find that user section

Re: UploadMoD

hrm..

The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.

$pun_root is defined as

$pun_root = './';

and it is in the root..


I get this when i launch uploads.php.. ? anyone know what im doing wrong?

Re: UploadMoD

Very well done, I won't have to release my fixed version, this version looks much better! Good job!

7

Re: UploadMoD

Smartmonkey wrote:

hrm..

The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.

$pun_root is defined as

$pun_root = './';

and it is in the root..


I get this when i launch uploads.php.. ? anyone know what im doing wrong?

Hmm... the only thing comes in mind is that $pun_root points on wrong folder. This means you uploaded files in wrong folder. In archive you will find folder named upload. You should upload uploads.php, /lang, /plugins. Not upload folder itself.

8

Re: UploadMoD

Ultime, snapsolutions: thank you smile



Ataxy wrote:

what is there to change to make it work with 1.2.2 since its made for 1.2.1
ok found it just mod the installer script to accept v1.2.2

UploadMoD should work on any 1.2.x punnBB version. Mod doesn't affects code it just adds several files, same thing with db - it need 2 tables to be created. So, it won't work with new punbb versions only if data structure will be changed (i.e. new variable names, or certain data will be stored in other db table etc.). However i tested it only on 1.2.1 yet smile

Ataxy wrote:

ok i got it iinstalled but now how do one upload when you do your post there is no attachement option or anything
basicly where should i find that user section

www.yoursite.com/pun_folder/uploads.php

Also you can add link to uploader in nav menu. Go Administration/options. Find there "Additional menu items" and use something like

5 = <a href="uploads.php">Uploads</a>

9 (edited by erissiva 2005-02-26 10:38)

Re: UploadMoD

Loiso - That's not what's wrong...
I have the same problem. It has to do with the way that variables are being called.

I've gotten the page to load with the following code.
What I did was replace "$pun_root" with "PUN_ROOT", and "$language" with "$pun_user['language']".
Past that, I don't know what else to change.
Paste this as the "uploads.php" file. It should work...

<?php


define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';


$page_title=pun_htmlspecialchars($pun_config['o_board_title']).'  »  Uploader';
// Load the viewtopic.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/'.'topic.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/'.'uploads.php';


require PUN_ROOT.'header.php';

    $result = $db->query('SELECT * FROM '.$db->prefix.'uploads_conf WHERE g_id='.$pun_user['g_id']); 
    $upl_conf= $db->fetch_assoc($result);
    if (!$upl_conf) {
        $result = $db->query('SELECT * FROM '.$db->prefix.'uploads_conf WHERE g_id=0');        
        $upl_conf= $db->fetch_assoc($result);
    }    
    
   
     $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups') or error('Unable to get useergroups', __FILE__, __LINE__, $db->error()); 
     $i=0;
    while ($i < $db->num_rows($result)) {

        $groups[$i] = $db->fetch_assoc($result);
        $result2 = $db->query('SELECT * FROM '.$db->prefix.'uploads_conf WHERE g_id='.$groups[$i]['g_id']) or error('Unable to upload persmissions', __FILE__, __LINE__, $db->error());
        $perms[$i]= $db->fetch_assoc($result2);
        if (!$perms[$i]) {
            $result2 = $db->query('SELECT * FROM '.$db->prefix.'uploads_conf WHERE g_id=0');        
            $perms[$i]= $db->fetch_assoc($result2);
           }
         $i++;               
    }
    

  $allowed = array(".txt",".gif",".jpg",".jpeg",".png");
  $pics = array(".gif",".jpg",".jpeg",".png");

 ?>
 

<b><a href="./index.php"><?php echo pun_htmlspecialchars($pun_config['o_board_title']); ?></a></a>  »  <a href="uploads.php"><?php echo $lang_uploads['Uploader']; ?></a><?php //echo ' / '.$lang_uploads['File']; ?></b> 
<br><br>
<div class="block">
    <h2><span>Uploads</span></h2>
    <div class="box">
        <div class="inbox">
<?php
        if (!$upl_conf['p_view']) {
?>        
        <div id="announce" class="block">
            <h2><span><b>Not allowed</b></span></h2>
                <div class="box">
                    <div class="inbox">
                        <div><?php    echo '<b>You do not have permissons to access upload module. Please, contact Administration.</b>'; ?></div>
                    </div>
                </div>
        </div>
<?php    
}
  
elseif (!$_POST) { 
    $_POST['act']='';
    
    
?>
        
        <div class="inform">
        <fieldset>
            <legend>Upload file</legend>
            <div class="infldset">
                <form method="POST" action="uploads.php" enctype="multipart/form-data">
                    <p><b>Uploading Rules:</b><br><br>
                    - You can use the upload to upload image and text with the following extention. (.txt, .gif, .jpg, .jpeg, .png)<br>
                    - The file must be under <?php echo round($upl_conf['u_fsize'] / 1024).'KB'; ?> <br>
                    - Please use a sensible file name or i will remove the file, if anyone abuses this uploader, it will be removed.<br><br>
                    <input type="file" name="file" size="30"><br><br>
                    <input type="hidden" name="user_id" value="<?php echo $pun_user['id']; ?>">
                    <input type="hidden" name="user_name" value="<?php echo $pun_user['username']; ?>">
                    <input type="submit" name="act" value="Upload"></p>
                </form>
            </div>
        </fieldset>    
        </div>    
        
        <div class="inform">
        <fieldset>
            <legend>File list</legend>
            <div class="infldset">
            Files below have been uploaded by users and may be malicous or contain inapropriate content. Click on a file to download. If you find any inapropriate content, please report to Administrator.<br><br>
                <table class="punmain" cellspacing="1" cellpadding="4">
                     <tr class="punhead">
                        <td class="punhead" style="width: 20%"><?php echo $lang_uploads['File']; ?></td>    
                        <td class="punhead" style="width: 5%"><?php echo $lang_uploads['Size']; ?></td>
                        <td class="punhead" style="width: 14%"><?php echo $lang_uploads['Posted by']; ?></td>
    <?php
            if($upl_conf['p_delete'])
                  echo '    <td class="punhead" style="width: 14%; white-space: nowrap">'.$lang_uploads['Delete'].'</td></tr>';        
                if($upl_conf['p_globalview']) {
                $result = $db->query('SELECT * FROM '.$db->prefix.'uploaded') or error('Error getting file list', __FILE__, __LINE__, $db->error());
            } else $result = $db->query('SELECT * FROM '.$db->prefix.'uploaded WHERE id ='.$pun_user['id']) or error('Error getting file list', __FILE__, __LINE__, $db->error());
            while($info = $db->fetch_assoc($result))    {
    ?>
                    <tr class="puntopic">
    <?php
            $ext = strtolower(strrchr($info['file'],'.'));
            if(in_array($ext,$pics))
                echo'                    <td class="puncon1"><a href="uploaded/'.$info['file'].'">'.$info['file'].'</td>';
            else
                echo'                    <td class="puncon1"><a href="./uploaded/'.$info['file'].'">'.$info['file'].'</td>';
    ?>
                    <td class="puncon2"><?php echo round(filesize('./uploaded/'.$info['file']) / 1024).'KB'; ?></td>
                    <td class="puncon1"><?php echo '<a href="profile.php?id='.$info['id'].'">'.$info['user'].'</a>'; ?></td>
    <?php
            if($upl_conf['p_globaldelete'])
                echo '                    <td class="puncon1"><form method="POST" action="uploads.php" enctype="multipart/form-data"><input type="hidden" name="delfile" value="'.$info['file'].'"><input type="submit" name="act" value="Delete"></form></td>';
            elseif ($upl_conf['p_delete']){
                if ($info['id'] == $pun_user['id']) echo '<td class="puncon1"><form method="POST" action="uploads.php" enctype="multipart/form-data"><input type="hidden" name="delfile" value="'.$info['file'].'"><input type="submit" name="act" value="Delete"></form></td>';
                else echo '                    <td class="puncon1">N/A</td>';
            }
    ?>
                    </tr>
    <?php
            }
    ?>
                </table>
                
            </div>
        </fieldset>    
        </div>
        
        
        </div>
    </div>
</div>


    

  
<?php } 
  
  
  
elseif ($_POST['act']=='Upload')  {
    
    if(($upl_conf['p_upload'] <> 1)) error('No permission', __FILE__, __LINE__, $db->error());
    $ext = strtolower(strrchr($file_name,'.'));
    if($file_name == "")
      error('No file selected for upload', __FILE__, __LINE__, $db->error());
    else if(file_exists('./uploaded/'.$file_name))
      error('File already exists', __FILE__, __LINE__, $db->error());
    else if($file_size > $upl_conf['u_fsize'])
      error('File was too big', __FILE__, __LINE__, $db->error());
    else if(!in_array($ext,$allowed))
      error('File is not a valid file type', __FILE__, __LINE__, $db->error());
    else {
        $result = $db->query('INSERT INTO '.$db->prefix.'uploaded(`file`,`user`,`id`) VALUES(\''.$file_name.'\',\''.$_POST['user_name'].'\',\''.$_POST['user_id'].'\')') or error('Unable to add upload data', __FILE__, __LINE__, $db->error());
        @copy($file, './uploaded/'.$file_name) or error('Could not copy file to server', __FILE__, __LINE__, $db->error());

?>        
<div class="inform">
    <fieldset>
        <legend>Uploading...</legend>
        <div class="infldset">
            <div><?php    echo '<b>File has been uploaded to <a href="./uploaded/'.$file_name.'">'.$pun_config['o_base_url'].'/uploaded/'.$file_name.'</a></b>'; ?></div>
        </div>
    </fieldset>
</div>
<?php

        if(in_array($ext,$pics)) echo '<img src="./uploaded/'.$file_name.'"><br><br>';
    }
}
elseif($_POST['act']=='Delete') {
    

    if(($upl_conf['p_delete'] <> 1)&&($upl_conf['p_globaldelete'] <> 1)) error('No permission', __FILE__, __LINE__, $db->error());

    if(!file_exists('./uploaded/'.$delfile))
      error('File doesn\'t exist', __FILE__, __LINE__, $db->error());
    else {
        unlink('./uploaded/'.$delfile);
        $result = $db->query('DELETE FROM '.$db->prefix.'uploaded WHERE file=\''.$delfile.'\'') or error('Unable to delete data', __FILE__, __LINE__, $db->error());
?>
<div class="inform">
    <fieldset>
        <legend>Deleting...</legend>
        <div class="infldset">
            <div><?php    echo $delfile.' removed from the uploader.'; ?></div>

        </div>
    </fieldset>
</div>
    
<?php
    }
}

?>

<?php

$footer_style = 'index';
require PUN_ROOT.'footer.php';

The only problems that I get with it is that I get a wierd error:
"Notice: Undefined index: Uploader in /home/adonis/public_html/bb/uploads.php on line 45" which has to do with the way things are being defined (again).

Also, it won't let me upload. It keeps saying that I need to select something to upload, even when I have...

Re: UploadMoD

you might want to consider putting the table of files in its own box with the blocktable class so it looks more styled

Re: UploadMoD

erissvia.. thanks that at least allowed me to view the page.. but I am also getting the same error

An error was encountered
Error: No file selected for upload.

Re: UploadMoD

Smartmonkey wrote:

erissvia.. thanks that at least allowed me to view the page.. but I am also getting the same error

An error was encountered
Error: No file selected for upload.

Yuppers....Same error I keep getting. I just think that some variables weren't transferred over correctly from version to version.

Re: UploadMoD

Cool smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."

14

Re: UploadMoD

Loiso wrote:
Ataxy wrote:

what is there to change to make it work with 1.2.2 since its made for 1.2.1
ok found it just mod the installer script to accept v1.2.2

UploadMoD should work on any 1.2.x punnBB version. Mod doesn't affects code it just adds several files, same thing with db - it need 2 tables to be created. So, it won't work with new punbb versions only if data structure will be changed (i.e. new variable names, or certain data will be stored in other db table etc.). However i tested it only on 1.2.1 yet smile

No but thats it what i am saying is that all i had to change was that line
$punbb_versions    = array('1.2.2');

Loiso wrote:
Ataxy wrote:

ok i got it iinstalled but now how do one upload when you do your post there is no attachement option or anything
basicly where should i find that user section

www.yoursite.com/pun_folder/uploads.php

Also you can add link to uploader in nav menu. Go Administration/options. Find there "Additional menu items" and use something like

5 = <a href="uploads.php">Uploads</a>

Ok here is my problem when i make a link that points to uploads.php i get this message:
The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.
And yes i did upload the content of the upload folder to root and not the upload folder to root.
so now i can basicly access the admin plugin and set right for user but i can get to upload stuff to the uploaded folder

15 (edited by Smartys 2005-02-26 12:39)

Re: UploadMoD

Take a look at erissiva's code: the replacements that were done are correct to fix it

*oh yes, go 300th post! big_smile*

16 (edited by Ataxy 2005-02-26 12:56)

Re: UploadMoD

ok i have made the change in the uploads.php file with erassiva code so now i am able to get to uploads.php but i get this
http://www.sitesled.com/members/ataxy/uploerr.JPG
as for the rest it seems to work perfectly i have upload one file and i did not get any error message

Re: UploadMoD

Yup, I got that too: and I couldn't upload (but that's unrelated) smile

Change
<?php echo $lang_uploads['Uploader']; ?>
to
<?php echo 'Uploader'; ?>

18 (edited by Ataxy 2005-02-26 13:05)

Re: UploadMoD

Smartys wrote:

Yup, I got that too: and I couldn't upload (but that's unrelated) smile

Change
<?php echo $lang_uploads['Uploader']; ?>
to
<?php echo 'Uploader'; ?>

thx smartys work perfect now

19

Re: UploadMoD

erissiva wrote:

Loiso - That's not what's wrong...
I have the same problem. It has to do with the way that variables are being called.

I've gotten the page to load with the following code.
What I did was replace "$pun_root" with "PUN_ROOT", and "$language" with "$pun_user['language']".
Past that, I don't know what else to change.
Paste this as the "uploads.php" file. It should work...


Also, it won't let me upload. It keeps saying that I need to select something to upload, even when I have...

Yep, you are right. There were couple variables which i forgot to port from punUpload. I fixed $pun_user['language'], but left $pun_root as is. For some reason on my local windows machine PUN_ROOT definition doesn't works, however using $pun_root on linux web server seems ok, just tested it.

About  "No file selected". For me it works fine, however the way variables were passed wasn't "clean". I added some code in uploads.php, hope it will work for you.

Also there was a little bug in lang file for UploadMoD. That's why ppl were getting that undefined index message (uploads.php on line 45).

I re-uploaded fixed release, please download it again. Hope this time it will work smooth smile

20 (edited by Loiso 2005-02-26 13:20)

Re: UploadMoD

Smartys wrote:

Yup, I got that too: and I couldn't upload (but that's unrelated) smile

Change
<?php echo $lang_uploads['Uploader']; ?>
to
<?php echo 'Uploader'; ?>

Heh, yeah that will work, but no multilanguage support then tongue

One more thing. Upload.php requires /include/common.php file where you can find

if (!defined('PUN_ROOT'))
    exit('The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.');

So you have to define PUN_ROOT constant. This can be done either in common.php file (so you won't need to define it again for other modules) or in uploads.php before you include common.php

Edit:

To close matter with PUN_UPLOAD constant i just added to uploads.php

if (!defined('PUN_ROOT')) define('PUN_ROOT','./');

Updated archive.

21 (edited by Smartys 2005-02-26 13:20)

Re: UploadMoD

lol, I don't intend on using it, just on testing it smile

You still didn't change install_mod.php to accept 1.2.2

Oh, and I just downloaded it: it looks like the exact same thing to me

22

Re: UploadMoD

ooops... fixed it. Thanks Smartys smile

23

Re: UploadMoD

well great job Loiso and thx to those that helped in finding the problem

Re: UploadMoD

Well diff error message now:

An error was encountered
Error: Could not copy file to server.

root/uploaded directory should have proper access... sad dunno whats going on

25 (edited by erissiva 2005-02-26 18:31)

Re: UploadMoD

Smartmonkey wrote:

Well diff error message now:

An error was encountered
Error: Could not copy file to server.

root/uploaded directory should have proper access... sad dunno whats going on

Same error here...

BIGGER ERROR! (i wish I could make this in neon...oh, wait - I can!)

Um, Loiso?
In your archive, you might wanna take out that fake "lang>English>common.php". That really screwed up my forum when I uploaded the whole directory through FTP.

Thanks.


Could any of these issues possibly be bacause of slight differences in 1.2.* and 1.2.2, or is it the differences in 1.1.5 and 1.2.*?