1
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 :: getImgListAsArray( XOOPS_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( '', "
. 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 :: getImgListAsArray( XOOPS_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', ' ' );
$actionimage_tray -> addElement( $actionimage_select );
$actionimage_tray -> addElement( new XoopsFormLabel( '', "
. 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_exists( XOOPS_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_exists( XOOPS_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!