1
kerkyra
Xoops Uploader Class
  • 2009/12/17 12:38

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


Hi does anybody have a problem with the XOOPS uploader class? It used to work for me but now it returns an empty $_Files['tmp_name'] and uploads nothing.

Furthermore using fck editor when trying to upload a pic through the uploader i get a message that the file uploaded succesfully but the file is not there! This happens in 2.3.2 and 2.4.2 any ideas?

2
trabis
Re: Xoops Uploader Class
  • 2009/12/17 13:36

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I need you to show me some code, please.

3
kerkyra
Re: Xoops Uploader Class
  • 2009/12/19 14:49

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


hi mate sorry for the delay,

the form code is

Quote:

echo "
"._MD_UPLOAD_IMAGE."














and the code to get what is posted is

Quote:

global $xoopsDB, $_POST, $myts, $eh;
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
include_once XOOPS_ROOT_PATH.'/class/module.errorhandler.php';

$lid = $myts->makeTboxData4Save($_POST["lid"]);
$destination_path = XOOPS_ROOT_PATH."/modules/myreviews/images/shots/";

$allowed_mimetypes = array('image/gif', 'image/jpeg','image/png');
$maxfilesize = 4194304;
$maxfilewidth = 800;
$maxfileheight = 800;
$uploader = new XoopsMediaUploader($destination_path, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
$uploader->setPrefix("shot");
$x=0;
if ($uploader->fetchMedia($_POST['xoops_upload_file'][$x]))
{
if (!$uploader->upload())
{
$result = $uploader->getErrors();
echo $result;

} else //update db
{
$logourl = $uploader->getSavedFileName();
$xoopsDB->query("INSERT INTO ".$xoopsDB->prefix("myreviews_images")." (lid, src) VALUES ($lid, $logourl)") or $eh->show("0013");
redirect_header("index.php",1,_MD_DBUPDATED);
}
}
else {
print_r($_POST);
}
}


whats weird is that this used to work, also the $_FILES['tmp_name'] is empty.

Finally the fckeditor image upload tool doesnt work! I asked the hosting company for any errors perhaps or php settings but they respond that this might be a XOOPS problem and that they see nothing weird in the servers configuration!!!

4
ghia
Re: Xoops Uploader Class
  • 2009/12/19 16:26

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


In your html form, there should be no spaces in the parameters.
Also suspicious is the $lid value parameter. Should it be not a value as eg 12?

5
kerkyra
Re: Xoops Uploader Class
  • 2009/12/20 3:20

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


i added the spaces before unchecking the html code button for pasting the code in here, the $lid var is working fine! no prob there actually! I also get the filename posted, i get no temp_name for that file though in the $_FILES var.:/

6
ghia
Re: Xoops Uploader Class
  • 2009/12/20 10:32

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Is your shots directory writable?
Any messages in debug?
PHP version?
Can you show the real html code, as obtained by a view selection source of your form in the browser?

7
kerkyra
Re: Xoops Uploader Class
  • 2009/12/20 14:06

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


php version 5.2.11

the shots directory is writable, XOOPS 2.4.2

no error messages in debug

The weird thing is that in XOOPS 2.3.2 this works (in the same server, same module)

also the image upload of fckeditor doesnt work while it says that the file was uploaded in both 2.3.2 and 2.4.2 and this used to work in both!!

I really cant get it....

8
ghia
Re: Xoops Uploader Class
  • 2009/12/21 0:26

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Made a test on 2.4.2 and had no problems. I used your code to create two programs in the XOOPS root. Only slight changes where made. Only one remark on your code: inconsistant closing tag for the input statements. tstupload.html
<html>
<
head>
head>
<
body>
<
form method='post' action='upload_image.php' enctype='multipart/form-data'>
<
input type="file" id="file" name="file" size="50" maxlength="60" />
<
input id="xoops_upload_file[]" type="hidden" value="file" name="xoops_upload_file[]"/><br><br>
<
input type="hidden" id="lid" name="lid" size="50" maxlength="60" value="123" />
<
input type="submit" class="button" name="submit" id="submit" value="Add pic" />
form>
body>html>
upload_image.php

include_once './mainfile.php';

global 
$xoopsDB$_POST$myts$eh;
include_once 
XOOPS_ROOT_PATH.'/class/uploader.php';
include_once 
XOOPS_ROOT_PATH.'/class/module.errorhandler.php';

$lid $_POST["lid"];
$destination_path XOOPS_ROOT_PATH."/uploads/";

$allowed_mimetypes = array('image/gif''image/jpeg','image/png');
$maxfilesize 4194304;
$maxfilewidth 800;
$maxfileheight 800;
$uploader = new XoopsMediaUploader($destination_path$allowed_mimetypes$maxfilesize$maxfilewidth$maxfileheight);
$uploader->setPrefix("shot");
$x=0;
if (
$uploader->fetchMedia($_POST['xoops_upload_file'][$x]))
{
if (!
$uploader->upload())
{
$result $uploader->getErrors();
echo 
$result;

} else 
//update db
{
$logourl $uploader->getSavedFileName();
// $xoopsDB->query("INSERT INTO ".$xoopsDB->prefix("myreviews_images")." (lid, src) VALUES ($lid, $logourl)") or $eh->show("0013");
// redirect_header("index.php",1,_MD_DBUPDATED);
echo 'ok'.$lid$logourl;
}
}
else {
print_r($_POST);
}

?>
Remark: Puts the file in uploads as eg shot4b2ebf7b64874.gif Shows OK with id = 123 and filename generated in stead of the actual database operation eg ok123shot4b2ebf7b64874.gif .

9
kerkyra
Re: Xoops Uploader Class
  • 2009/12/21 1:44

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


so any ideas what i should check? I know this code used to work fine...! What could have caused this and the fckeditor prob additionally?

10
ghia
Re: Xoops Uploader Class
  • 2009/12/21 9:17

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


You didn't try the two example programs?

Login

Who's Online

260 user(s) are online (123 user(s) are browsing Support Forums)


Members: 0


Guests: 260


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