1
TheFinni
uploading two files in one form using uploader.php xoops class
  • 2004/9/26 13:19

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Does anyone know if I can use the current XOOPS uploader file to upload two files in the same form?

I have modified Soapbox a little and would like to add an action picture as well. (i.e two pictures)

This is what I have done with my form:


// IMAGE
    // The article CAN have its own image :)
    // First, if the article's image doesn't exist, set its value to the blank file
    
if (!file_exists(XOOPS_ROOT_PATH "/" $xoopsModuleConfig['theteam_uploaddir'] . "/" $artimage) || !$artimage)
        {
        
$artimage "blank.png";
        } 
    
// Code to create the image selector
    
$graph_array = & XoopsLists :: getImgListAsArrayXOOPS_ROOT_PATH "/" $xoopsModuleConfig['theteam_uploaddir'] );
    
$artimage_select = new XoopsFormSelect'''artimage'$artimage );
    
$artimage_select -> addOptionArray$graph_array );
    
$artimage_select -> setExtra"onchange='showImgSelected("image5", "artimage", "" . $xoopsModuleConfig['theteam_uploaddir'] . "", "", "" . XOOPS_URL . "")'" );
    
$artimage_tray = new XoopsFormElementTray_AM_THETEAM_SELECT_IMG' ' );
    
$artimage_tray -> addElement$artimage_select );
    
$artimage_tray -> addElement( new XoopsFormLabel''"<br /><br /><img src='" XOOPS_URL "/" $xoopsModuleConfig['theteam_uploaddir'] . "/" $artimage "' name='image5' id='image5' alt='' />" ) );
    
$sform -> addElement$artimage_tray );

    
// Code to call the file browser to select an image to upload
    
$sform -> addElement( new XoopsFormFile_AM_THETEAM_UPLOADIMAGE'cimage'$xoopsModuleConfig['maxfilesize'] ), false );

//TN adding action image:
    
if (!file_exists(XOOPS_ROOT_PATH "/" $xoopsModuleConfig['theteam_uploaddir'] . "/" $actionimage) || !$actionimage)
        {
        
$actionimage "blank.png";
        } 
    
// Code to create the image selector
    
$graph_array = & XoopsLists :: getImgListAsArrayXOOPS_ROOT_PATH "/" $xoopsModuleConfig['theteam_uploaddir'] );
    
$actionimage_select = new XoopsFormSelect'''actionimage'$actionimage );
    
$actionimage_select -> addOptionArray$graph_array );
    
$actionimage_select -> setExtra"onchange='showImgSelected("image6", "actionimage", "" . $xoopsModuleConfig['theteam_uploaddir'] . "", "", "" . XOOPS_URL . "")'" );
    
$actionimage_tray = new XoopsFormElementTray('Select action image''&nbsp;' );
    
$actionimage_tray -> addElement$actionimage_select );
    
$actionimage_tray -> addElement( new XoopsFormLabel''"<br /><br /><img src='" XOOPS_URL "/" $xoopsModuleConfig['theteam_uploaddir'] . "/" $actionimage "' name='image6' id='image6' alt='' />" ) );
    
$sform -> addElement$actionimage_tray );
    
// Code to call the file browser to select an image to upload
    
$sform -> addElement( new XoopsFormFile('Upload action image''dimage'$xoopsModuleConfig['maxfilesize'] ), false );
//TN EOF action image


and then I tried to modify the function to my action image:

// ARTICLE IMAGE
        // Define variables
        
$error 0;
        
$word null;
        
$uid $xoopsUser -> uid();
        
$submit 1;
        
$date time();

        if ( 
$HTTP_POST_FILES['cimage']['name'] != "" )
            {
            include_once 
XOOPS_ROOT_PATH '/class/uploader.php';

            if ( 
file_existsXOOPS_ROOT_PATH "/" $xoopsModuleConfig['theteam_uploaddir'] . "/" $HTTP_POST_FILES['cimage']['name'] ) )
                {
                
redirect_header"index.php"1_AM_THETEAM_FILEEXISTS );
                } 
            
$allowed_mimetypes = array( 'image/gif''image/jpeg''image/pjpeg''image/x-png' );

            
uploading($allowed_mimetypes$HTTP_POST_FILES['cimage']['name'], "index.php"0$xoopsModuleConfig['theteam_uploaddir']);
        
            
$artimage $HTTP_POST_FILES['cimage']['name'];
            }
        elseif (
$HTTP_POST_VARS["artimage"] != "blank.png")
            {
            
$artimage $myts -> addSlashes$HTTP_POST_VARS["artimage"] );
            } 
        else
            {
            
$artimage '';
            } 

//TN action image:
// ARTICLE IMAGE
        // Define variables
        
$error 0;
        
$word null;
        
$uid $xoopsUser -> uid();
        
$submit 1;
        
$date time();

        if ( 
$HTTP_POST_FILES['dimage']['name'] != "" )
            {
            include_once 
XOOPS_ROOT_PATH '/class/uploader.php';

            if ( 
file_existsXOOPS_ROOT_PATH "/" $xoopsModuleConfig['theteam_uploaddir'] . "/" $HTTP_POST_FILES['dimage']['name'] ) )
                {
                
redirect_header"index.php"1_AM_THETEAM_FILEEXISTS );
                } 
            
$allowed_mimetypes = array( 'image/gif''image/jpeg''image/pjpeg''image/x-png' );

            
uploading($allowed_mimetypes$HTTP_POST_FILES['dimage']['name'], "index.php"0$xoopsModuleConfig['theteam_uploaddir']);
        
            
$actionimage $HTTP_POST_FILES['dimage']['name'];
            }
        elseif (
$HTTP_POST_VARS["actionimage"] != "blank.png")
            {
            
$actionimage $myts -> addSlashes$HTTP_POST_VARS["actionimage"] );
            } 
        else
            {
            
$actionimage '';
            } 
//TN EOF action image


I have tried to remove the "$artimage" and then my action image uploads just fine. I am getting both filenames saved to the DB in any instance so I know I have set-up that part properly. I'm thinking maybe the uploader.php is not euipped to upload two files at a time. But I'm probably wrong...Just don't know how to proceed.

Any tips would be welcomed. :)

Thank you!

2
TheFinni
Re: uploading two files in one form using uploader.php xoops class
  • 2004/10/4 11:41

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


I put this issue on the shelf for a while...

Now I'm back trying to solve this.

I have come to some conclusions regarding this. Whichever image form upload I put ahead in the form is the image that will be uploaded properly. So...I looked at the source code before submitting the form. This is what I get:

Artimage:
<input type='hidden' name='MAX_FILE_SIZE' value='250000' />
<
input type='file' name='cimage' id='cimage' />
<
input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='cimage' />

and:

Actionimage:
<input type='hidden' name='MAX_FILE_SIZE' value='250000' />
<
input type='file' name='dimage' id='dimage' />
<
input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='dimage' />

Currently I am thinking that ther reason the second image won't upload properly is because of the xoops_upload_file[] being the same for both instances.

So I looked up the code and found it in XOOPS_ROOT/class/xoopsform/formfile.php. The code for outputting the hidden uppload field looks as follows:

function render(){
        return 
"<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."' /><input type='file' name='".$this->getName()."' id='".$this->getName()."'".$this->getExtra()." /><input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='".$this->getName()."' />";
    }


So I thought if I could change the 'xoops_upload_file[]' to a unique name the images would upload fine. Therefore I changed it to 'xoops_upload_file[".$this->getName()."]' and the hidden field became unique...AND SHOULD WORK...but with this setting none of the images will upload. Does this have to do with the uploader class only working when the name is exactly 'xoops_upload_file[]'?

As always, would appreciate some expert advice. :)

Thank you!

3
TheFinni
Re:uploading two files in one form using uploader.php xoops class
  • 2004/10/6 8:53

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


anyone?

4
Mithrandir
Re:uploading two files in one form using uploader.php xoops class

Have you tried with
xoops_upload_file[0] and xoops_upload_file[1] instead of by name?

5
TheFinni
Re:uploading two files in one form using uploader.php xoops class
  • 2004/10/7 7:48

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Mithrandir,
Thank you for your suggestion. I tried it out but the second image (file) doesn't seem to want to upload...

I am getting a: "Filename is empty error" for the second file. However the first file does upload properly.

Do you think I have made an error elsewhere? or does the uploader class support uploading of two files in the same form?

Tack sa mycket!

6
TheFinni
Re:uploading two files in one form using uploader.php xoops class
  • 2004/10/7 8:00

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Actually,
Now that I further tested...It seems strange. Whichever image I assign: xoops_upload_file[0] will work. But if I assign xoops_upload_file[1] for the first image upload and then xoops_upload_file[2] none of them work. Does the [0] represent the same as in []?

Login

Who's Online

163 user(s) are online (100 user(s) are browsing Support Forums)


Members: 0


Guests: 163


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits