1
photek
Upload Form
  • 2004/5/28 13:35

  • photek

  • Just popping in

  • Posts: 34

  • Since: 2004/4/10


I was wondering, is there anyway, to add an upload form to a block, that will only allow .gif and .jpg images? id like to allow my users a quick upload form for them to store there files on my server, sort of like a user storage.

i dont know a lot of php code, so i was wondering, if it were possible..

2
intel352
Re: Upload Form
  • 2004/5/28 13:38

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


there's an upload class provided with xoops, xoopsroot/class/uploader.php

i would suggest getting MyDownloads v2 beta (don't remember the beta version), i remember people saying it used the upload capabilities, so that might show you how to implement an upload form


3
photek
Re: Upload Form
  • 2004/5/28 13:58

  • photek

  • Just popping in

  • Posts: 34

  • Since: 2004/4/10


thanks for the help!

4
intel352
Re: Upload Form
  • 2004/5/28 14:13

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


heh, np, if you need help with the code, post

5
winsion
Re: Upload Form
  • 2004/5/28 14:23

  • winsion

  • Just popping in

  • Posts: 55

  • Since: 2003/11/23


Example code upload in admin of a module :

include(
"admin_header.php");


$op 'form'


function 
form() {

include 
XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$my_form = new XoopsThemeForm("Upload""form""index.php");
$my_form->setExtra"enctype='multipart/form-data'" ) ; 
$img_box = new XoopsFormFile("Image""photo"$max_imgsize);
$img_box->setExtra"size ='50'") ;
$my_form->addElement($img_box); 
$button_tray = new XoopsFormElementTray('' ,'');
$button_tray->addElement(new XoopsFormButton('''post',"Submit"'submit'));
$my_form->addElement($button_tray);
$my_form->display();
}



foreach ( 
$_POST as $k => $v ) { 
${
$k} = $v
}
if ( isset(
$post) ) {
$op 'post';
}

switch (
$op) {


case 
"post"
$max_imgsize 100000
$max_imgwidth 500
$max_imgheight 500
$allowed_mimetypes = array('image/gif''image/jpeg''image/pjpeg''image/x-png');
$img_dir XOOPS_ROOT_PATH "/modules/mymodule/images" ;

include_once(
XOOPS_ROOT_PATH."/class/uploader.php");
$field $_POST["xoops_upload_file"][0] ; 

if( !empty( 
$field ) || $field != "" ) { 


$uploader = new XoopsMediaUploader($img_dir$allowed_mimetypes$max_imgsize$max_imgwidth$max_imgheight);
$uploader->setPrefix'img' ) ;
if( 
$uploader->fetchMedia$field ) && $uploader->upload() ) { 
$photo=$uploader->getSavedFileName();

} else { 
echo 
$uploader->getErrors();
}
}

    

break; 

case 
'form':
default:
xoops_cp_header();

form();

xoops_cp_footer();
break;
}
?>

6
intel352
Re: Upload Form
  • 2004/5/28 14:35

  • intel352

  • Module Developer

  • Posts: 824

  • Since: 2003/11/23


i didn't think about that, i don't usually upload templates via admin, but nice find

7
photek
Re: Upload Form
  • 2004/5/28 14:44

  • photek

  • Just popping in

  • Posts: 34

  • Since: 2004/4/10


sweet! thanks guys

8
phillipd
Re: Upload Form
  • 2005/1/27 16:51

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


Whenever I use "XoopsFormFile" to get a path to a file, when I POST it all I get is the filename, the directory part is missing. Do you have this same problem? What am I missing here???

Thanks

Doug P

9
phillipd
Re: Upload Form
  • 2005/2/1 21:37

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I've had some luck with the code that winsion posted, but I don't understand how this line works:

$field = $_POST["xoops_upload_file"][0] ;

Where does "xoops_upload_file" come from? It's not in the form code. What is it? Is it a XOOPS thing? And it still, when echoed to the browser, only shows the filename. The path component is missing. But it works, the file is uploaded to the images dir. This is really confounding me, it looks like magic! I would really like to understand this XoopsFormFile mechanism so I may use it with some confidence. Any help here is GREATLY appreciated. What piece of information am I missing?

Thanks

Doug P

Login

Who's Online

249 user(s) are online (208 user(s) are browsing Support Forums)


Members: 0


Guests: 249


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