1
kerkyra
Uploading files
  • 2008/4/8 10:57

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


hallo there,

does anyone know if there is a specific class to handle uploading files on the server using xoops?? I'm trying to make a module to upload files like pictures, flash and videos. Anyone have any idea?

thanks
whttp://www.guidemap.gr - Beta is out...

2
Catzwolf
Re: Uploading files
  • 2008/4/8 11:06

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Yes there is the xoopsUploader Class, you will find this in XOOPS_ROOT/class/uploader.php.

You will also find instructions on its usage inside the file itself. Lets know how you get on. :)

Catz

3
kerkyra
Re: Uploading files
  • 2008/4/8 11:24

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


thanks for your reply mate! :) i will, have a nice one
whttp://www.guidemap.gr - Beta is out...

4
kerkyra
Re: Uploading files
  • 2008/4/10 14:17

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


hallo there, trying to use the uploader class, having a few probs though.

I have setup a form through php like the following

Quote:


$imagesdir = XOOPS_ROOT_PATH."/modules/../images/";

echo "\n";

echo "";
echo "";
echo "\n";
echo " ";
echo "";
echo "";}


now in the addimage function i have this code Quote:

include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$error =0;

$allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png');
$maxfilesize = 50000;
$maxfilewidth = 450;
$maxfileheight = 650;

$i=0;

$imagetitle="filename";
$filename = basename($HTTP_POST_FILES[$imagetitle]['name']);

$uploader = new XoopsMediaUploader($imagesdir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);

if ($uploader->fetchMedia($filename)) {
if (!$uploader->upload()) {
echo $uploader->getErrors();
} else {
echo '

File uploaded successfully!

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

$name=$uploader->getSavedFileName();

$sql = sprintf...



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



when i click the submit button all i get is there were errors during uploading and file not found. do i pass the correct parameter ($filename) to uploads()???

is this class used to any modules where i can see an example?

anyone has any ideas of what i'm doing wrong? Thanks
whttp://www.guidemap.gr - Beta is out...

5
Catzwolf
Re: Uploading files
  • 2008/4/10 15:15

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Try just using this:

($uploader->fetchMedia($_FILES['filename]))


The uploader deals with $_FILES['array']['name'] anyway so you don't need to do all that.

If the above line doesn't work try $_POST['filename'] instead.

Been a while sine i have used this clas directly as this, and yes under normal circumstances that would work, but we are dealing with XOOPS here lol

John

6
kerkyra
Re: Uploading files
  • 2008/4/11 12:36

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


well it doesnt seem to work for me! I tried using xoopsform and worked just fine passing this

Quote:
if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {


but xoopsforms are not very elegant! i need to make a custom form for this! how should i do it? any ideas?
whttp://www.guidemap.gr - Beta is out...

7
kerkyra
Re: Uploading files
  • 2008/4/13 12:55

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


bump?
whttp://www.guidemap.gr - Beta is out...

8
phppp
Re: Uploading files
  • 2008/4/13 13:41

  • phppp

  • XOOPS Contributor

  • Posts: 2857

  • Since: 2004/1/25


Custom form, what exactly do you need?

9
kerkyra
Re: Uploading files
  • 2008/4/13 16:43

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


i tried to use a custom form to upload an image file but with no luck using the uploader class, so i did it with xoopsform class which seems to work fine with the uploader class.

There are a few drawbacks though! i have no control on how the form looks, or the name of the input field for the file to be uploaded! so i cant have a for loop for example to show me three input fields named filename1,filename2,filename3...

With a few files the uploader class doesnt work. I uploaded a jpg file just fine and then i tried another one and it said file not loaded! the second file is still a jpg file and the filesize, width and height within the limits. Any ideas?
whttp://www.guidemap.gr - Beta is out...

10
kerkyra
Re: Uploading files
  • 2008/4/17 14:54

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


hallo there the image file uploading is working fine now! I'm using this code now, to upload media files, and while it seems to work with wav files it doesnt with mp3s anybody have a suggestion?
whttp://www.guidemap.gr - Beta is out...

Login

Who's Online

393 user(s) are online (261 user(s) are browsing Support Forums)


Members: 0


Guests: 393


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