1
kaotik
uploader.php and Notice: Undefined index:
  • 2004/9/29 14:28

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I'm getting this error:
Notice: Undefined index: upload_file_name in c:\mailattach.php on line 53

Errors Returned While Uploading
File not found

Here's the line:
if ($uploader->fetchMedia($HTTP_POST_VARS['upload_file_name'])) {

can someone help me?

Here's the entire code:
include_once 'uploader.php';
$allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
$maxfilesize = 50000;
$maxfilewidth = 120;
$maxfileheight = 120;
$uploader = new XoopsMediaUploader('/home/xoops/uploads', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
if ($uploader->fetchMedia($HTTP_POST_VARS['upload_file_name'])) {
if (!$uploader->upload()) {
echo $uploader->getErrors();
} else {
echo '

File uploaded successfully!

';
echo 'Saved as: ' . $uploader->getSavedFileName() . '
';
echo 'Full path: ' . $uploader->getSavedDestination();
}
} else {
echo $uploader->getErrors();
}
?>

2
sbkiller
Re: uploader.php and Notice: Undefined index:
  • 2004/9/29 15:44

  • sbkiller

  • Just can't stay away

  • Posts: 461

  • Since: 2004/6/9 2


Is this part of Xoops?

3
kaotik
Re: uploader.php and Notice: Undefined index:
  • 2004/9/29 15:59

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


yes, it's the uploader.php file found in /class.
I copied the initial part into a different file:

include_once 'uploader.php';
$allowed_mimetypes = array('image/gif''image/jpeg''image/pjpeg''image/x-png');
$maxfilesize 50000;
$maxfilewidth 120;
$maxfileheight 120;

$uploader = new XoopsMediaUploader('/home/xoops/uploads'$allowed_mimetypes$maxfilesize$maxfilewidth$maxfileheight);
if (
$uploader->fetchMedia($_POST[img][0])) {
if (!
$uploader->upload()) {
echo 
$uploader->getErrors();
} else {
echo 
'

File uploaded successfully!

'
;
echo 
'Saved as: ' $uploader->getSavedFileName() . '';
echo 
'Full path: ' $uploader->getSavedDestination();
}
} else {
echo 
$uploader->getErrors();
}
?>


then copied uploader.php into the same directory (just for testing purposes)
I've read the comments regarding this line in uploader.php
@param   string  $media_name Name of the file field
     
* @param   int     $index      Index of the file (if more than one uploaded under that name)

but can't understand what it's asking for. can you help me plz?

4
kaotik
Re: uploader.php and Notice: Undefined index:
  • 2004/9/29 16:02

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


The original line was:
if ($uploader->fetchMedia($HTTP_POST_VARS['uploade_file_name'])) {

I've just been tring diferent things there tring to get it to work

5
TheFinni
Re:uploader.php and Notice: Undefined index:
  • 2004/10/10 12:37

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Hi Kaotik,
Were you able to solve this issue? I am having a similar problem...

6
kaotik
Re:uploader.php and Notice: Undefined index:
  • 2004/10/10 12:57

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I couldn't get that to work so I replaced it with a small piece of code I found on the net which works quite nicely. I adapted it to work with my XOOPS module so you might want to go over and review the variables. Here it is:

include("../../mainfile.php");
include(
"cache/config.php");
global 
$attachmentdir$maxattachsize;


$site_name $_SERVER['HTTP_HOST'];
$url_dir XOOPS_ROOT_PATH "modules/webmailfx";
$url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir $attachmentdir "/";
$upload_url $url_dir."/"$attachmentdir ."/";
$message ="";
print 
$message;

if (!
is_dir($attachmentdir)) {
    die (
"Attachment directory doesn't exist or isn't properly configured");
}

if (
$_FILES['userfile']) {
    
$message do_upload($upload_dir$upload_url);
}
else {
    
//$message = "Invalid File Specified.";
}


print 
$message;

function 
do_upload($upload_dir$upload_url) {

    
$temp_name $_FILES['userfile']['tmp_name'];
    
$file_name $_FILES['userfile']['name']; 
    
$file_type $_FILES['userfile']['type']; 
    
$file_size $_FILES['userfile']['size']; 
    
$result    $_FILES['userfile']['error'];
    
$file_url  $upload_url.$file_name;
    
$file_path $upload_dir.$file_name;

    
//File Name Check
    
if ( $file_name =="") { 
        
$message WFX_ATTINVALID;
        return 
$message;
    }
    
//File Size Check
    
else if ( $file_size $maxattachsize) {
        
$message WFX_ATTFILESIZE $adasdas "k";
        return 
$message;
    }
    
//File Type Check
    
else if ( $file_type == "text/plain" ) {
        
$message WFX_ATTFILETYPE;
        return 
$message;
    }

    
$result  =  move_uploaded_file($temp_name$file_path);
    
//$message = ($result)?"File url $file_url" :
              
"Somthing is wrong with uploading a file.";

    return 
$message;

}

echo 
"emailform" id="upload" ENCTYPE="multipart/form-data" method="post">

"
    ."file" id="userfile" name="userfile">"
    
."submit" name="upload" value="Upload">

"
    
."

submit" name="submit" onClick="window.close()" value="Close">

"
;
echo 
$file_name;
?>

7
Draven
Re:uploader.php and Notice: Undefined index:
  • 2004/10/10 13:17

  • Draven

  • Module Developer

  • Posts: 337

  • Since: 2003/5/28


Undefined index means that the array key you are looking for in the HTTP_POST_VARS doesn't exist. Ensure that that the variable it is looking for is being past via POST and not get GET, or that the var is being passed at all.

It sounds to me as though the Filename of the file you are trying to upload is either not being passed, or is being passed using the wrong variable name.

8
TheFinni
Re:uploader.php and Notice: Undefined index:
  • 2004/10/10 13:33

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Thanks Kaotik,
I don't know if I'm willing to give up on the xoopsuploader quite yet. It seems to be working in other parts of the site.

I think Draven has a point. It's pretty much the same conclusion I have come to...but I can't figure out why my variable is not being passed on?

Basically I am trying to create an image-upload for the Xoopspartners module. I think it is silly to have to input the src code for each images. Especially for those who don't know a squat about img src code(my client).

Plus there's a dissadvantage if your partner removes or changes their logo without you knowing it. (Which can currently be seen on Xoops's site where the Brazilian Support site logo is missing) ex.

https://xoops.org/modules/xoopspartners/

Anyhow, I hope someone could give me a hand with this. Basically I have made an instance where I am trying to get the image upload to work without the other form items. Here's my code:

function imageUpload()
{
    
$xoopsDB =& Database::getInstance();
    
$myts =& MyTextSanitizer::getInstance();
    
xoops_cp_header();
    echo 
"

"._MD_PARTNERADMIN."

"
;
    include 
XOOPS_ROOT_PATH."/class/xoopsformloader.php";
    
$form       = new XoopsThemeForm(_MD_ADDPARTNER"addform""index.php");
    
$op_hidden  = new XoopsFormHidden("op""uppImage");
    
$submit_button = new XoopsFormButton("""submit""Upload""submit");
    
$form->addElement($formweight);
    
//TN removed: $form->addElement($formimage);
    //TN trying to add image upload
    
$form -> addElement( new XoopsFormFile'Upload an image''partnerlogo''250000' ), false );
    
//TN EOF
    
$form->addElement($op_hidden);
    
$form->addElement($submit_button);
    
$form->display();
    
xoops_cp_footer();
}

function 
uppImage()
{

    
$allowed_mimetypes = array('image/gif''image/jpeg''image/pjpeg''image/x-png');
    
$maxfilesize 50000;
    
$maxfilewidth 120;
    
$maxfileheight 120;
    include_once(
XOOPS_ROOT_PATH."/class/uploader.php");
    
    
$uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH."/modules/xoopspartners/images/uploads/"$allowed_mimetypes$maxfilesize$maxfilewidth$maxfileheight);

    if (
$uploader->fetchMedia($HTTP_POST_VARS['partnerlogo'])) {
           if (!
$uploader->upload()) {
              echo 
$uploader->getErrors();
                } else {
                       echo 
'

File uploaded successfully!

'
;
                       echo 
'Saved as: ' $uploader->getSavedFileName() . '';
                       echo 
'Full path: ' $uploader->getSavedDestination();
                   }
                      } else {
    echo 
$uploader->getErrors();
  }

exit();
}


But I am getting the following error:

Errors Returned While Uploading
File not found
Notice [PHP]: Undefined variable: HTTP_POST_VARS in file c:\web\xoops\modules\xoopspartners\admin\index.php line 196

9
Draven
Re:uploader.php and Notice: Undefined index:
  • 2004/10/10 15:46

  • Draven

  • Module Developer

  • Posts: 337

  • Since: 2003/5/28


I don't have time to check your code thoroughly as I'm jus about to step out. Here's a few things I'd test to find out what's going on.

First, change the old $HTTP_POST_VARS['partnerlogo'] to the new $_POST['partnerlogo'].

Second, view the source code of the form you are using to upload and double check that the method is set to POST and not GET. Might want to just set your XoopsThemeForm to method POST.

$form       = new XoopsThemeForm(_MD_ADDPARTNER"addform""index.php""POST");


and last I would add a print_r to the begining of that second function so I could review all of the post vars and make sure my vars are there.

function uppImage(){

print_r($_POST);

....

}


should be able to determine what's happening from that.

10
TheFinni
Re:uploader.php and Notice: Undefined index:
  • 2004/10/10 19:59

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Thank you Draven,
I did what you suggested. The upload function didn't complete however I got the following message from the "print_r($_POST);" you sugested:

Array ( [MAX_FILE_SIZE] => 250000 [partnerlogo] => C:\Documents and Settings\User\My Documents\My Pictures\mylogo.jpg [xoops_upload_file] => Array ( [0] => partnerlogo ) [op] => uppImage [submit] => Upload 

Errors Returned While Uploading
File not found

I don't completely understand the array. Why is there double backward slash in between the folders? Could this be the error?

Login

Who's Online

385 user(s) are online (302 user(s) are browsing Support Forums)


Members: 0


Guests: 385


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