11
TheFinni
Re:uploader.php and Notice: Undefined index:
  • 2004/10/11 6:14

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


I am still having problems. How important is the: enctype="multipart/form-data in the form? I managed to add it using:

$sform -> setExtra( 'enctype="multipart/form-data"' );

but the problem is still the same.

I also experiemented with an uploader found in Tinycontent and with that I get it to work...only the Tinycontent uploader allows you to upload all sort of files including txt. etc. I only want the image upload.

Please help. I am getting tired with this.

If you know of any tutorials on how to use the XOOPS uploader I would be grateful. i have search and searched but not found much. :(

12
Ewaan
Re:uploader.php and Notice: Undefined index:
  • 2005/1/18 23:16

  • Ewaan

  • Just popping in

  • Posts: 4

  • Since: 2005/1/18


The variable you need to pass to the function fetchMedia is

$_POST['xoops_upload_file'][0]

e.g.

$uploader->fetchMedia($_POST['xoops_upload_file'][0])


in the example given $_POST['xoops_upload_file'][0]==partnerlogo

13
Ewaan
Re:uploader.php and Notice: Undefined index:
  • 2005/1/28 9:46

  • Ewaan

  • Just popping in

  • Posts: 4

  • Since: 2005/1/18


If you have multiple images loop through $_POST['xoops_upload_file'] array:

//upload media
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$allowed_mimetypes = array('image/gif', 'image/jpeg', 'audio/mpeg');
$maxfilesize = 50000000;
$maxfilewidth = 4000;
$maxfileheight = 3000;

$uploadDir = '/uploads';
print_r($_POST['xoops_upload_file']);
print " count : ".count($_POST['xoops_upload_file']);
$uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH.$uploadDir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
if(isset($_POST['xoops_upload_file'][0]))
{
for($i=0;$i {
if($uploader->fetchMedia($_POST['xoops_upload_file'][$i]))
{
if (!$uploader->upload())
{
$errors[] = $uploader->getErrors();
}
else
{
$filename=$uploader->getSavedFileName() . '
';
$saved_path=$uploader->getSavedDestination();
$mediaType='';
$mediaType=$uploader->getMediaType();
$j=strpos($mediaType,'/');
$mediaType=substr($mediaType,++$j);
$file_path = XOOPS_ROOT_PATH.'/modules/myModule/media/';
$new_thumb_file=XOOPS_ROOT_PATH.$uploadDir.'/tmpT';
touch($new_thumb_file);
createThumbImage($saved_path,$new_thumb_file,$mediaType);
$name='uniqueName';
$s1=rename($new_thumb_file,$file_path.'thumbs/'.$name);
$new_large_file=XOOPS_ROOT_PATH.$uploadDir.'/tmpL';
touch($new_large_file);
createLargeImage($saved_path,$new_large_file,$mediaType);
$name='uniqueName';
$s2=rename($new_large_file,$file_path.'large/'.$name);

//delete orginal uploaded file
unlink($saved_pathh);
if(!$s1||!$s2)
{
//manage filesystem errors
}
}
}
else
{
//manage uploader errors
//$errors[] = $uploader->getErrors();
}
}
}



function createThumbImage($filename,&$new_file,$format)
{
// Set a maximum height and width
$width = 100;
$height = 100;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if($width && ($width_orig < $height_orig))
{
$width=($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}

// Resample

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
if($format=='jpeg')imagejpeg($image_p,$new_file);
if($format=='gif')imagegif($image_p,$new_file);
}

14
borisj
Re:uploader.php and Notice: Undefined index:
  • 2005/11/7 16:20

  • borisj

  • Just popping in

  • Posts: 2

  • Since: 2004/3/30


Hi guys, and sorry for my english,

I met the same issue, and I found a solution:

In fact, if I'm not wrong, what you need to understand is that only the variable's content you use in your XoopsFormFile function (fichier_profil for me), is used.
So don't make the FetchMedia test on the variable's name you used, but on the one use by the XOOPS class.

If my explanations do not seem clear to you, please take a look on the code below, as it worked for me.


switch($op) {

case 'do_upload':

$allowed_mimetypes = array('application/lua','image/png','image/gif','image/jpg');
$maxfilesize = 5000000;
$maxfilewidth = 5000000;
$maxfileheight = 5000000;
$uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH.'/modules/wowclan/profils',$allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);

if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
if (!$uploader->upload()) {
echo $uploader->getErrors();
} else {
echo '

Fichier uploadé avec succés!

';
echo 'Enregistré sous : ' . $uploader->getSavedFileName() . '
';
echo 'Chemin complet: ' . $uploader->getSavedDestination();
}
} else {
echo $uploader->getErrors();
}

break;

case 'default':
default:
$description = new XoopsFormFile("Selectionner votre profil", "fichier_profil", 5000000);
$op_hidden = new XoopsFormHidden("op", "do_upload");
$button = new XoopsFormButton("", "submit", "Uploader", "submit");

$form = new XoopsThemeForm("UPLOADER", "formulaire", "upload.php", "POST", true);

$form->setExtra( "enctype='multipart/form-data'" ) ;
$form->addElement($description);
$form->addElement($op_hidden);
$form->addElement($button);
$form->display();


break;

}

Login

Who's Online

415 user(s) are online (362 user(s) are browsing Support Forums)


Members: 0


Guests: 415


more...

Donat-O-Meter

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

Latest GitHub Commits