1
xsell
Try to upload , Always message File not Allowed.
  • 2009/12/22 5:00

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


Hello

So i Modfied this Code to Make Simple Upload Page , without useing XOOPS uploading class. but when i upload an allowed file like zip file , i always get error file not allowed .. when i allowed it as u may see in the code , the funny thing i have no problem uploading file if useing html Form post instaed the DHTML which i used below .. so wht could be Problem

this is the form file.

include("../../mainfile.php");

    
$xoopsOption['template_main']= "test_dhtml.html";
 include_once 
XOOPS_ROOT_PATH."/class/xoopsformloader.php";
include_once(
"../../header.php");
$xoopsTpl->assign('form0', $form = new XoopsThemeForm(_MI_TEST_INDEX_PAGE, "form_name", "send.php"));
$xoopsTpl->assign('upload', $t = new XoopsFormfile(_MI_TEST_YOUR_COMMENT, 'upload',50, 30));
$xoopsTpl->assign('uploads', $form->addElement($t));
$xoopsTpl->assign('send', $submit = new XoopsFormButton("", "submit", _MI_TEST_EMAIL_SEND_NOW, "submit"));
$xoopsTpl->assign('send1', $form->addElement($submit));
$xoopsTpl->assign('send1', $form->render());

    include(
"../../footer.php");


the process File.

<?php
include("../../mainfile.php");
include(
"../../header.php");
$allowed_ext = array('png','zip','PNG');

$ext = end(explode('.',$_FILES['upload']['name']));
$ran2 = rand().".";
$target = "up/";
$target = $target . $ran2.$ext;
if(
$_FILES['upload']['size'] > 50000000)
{
redirect_header(XOOPS_URL . "/modules/test/index.php" , 3, "".ATTACHMENTS2."");
}

if(
$message == NULL && !in_array($ext,$allowed_ext))  {

redirect_header(XOOPS_URL . "/modulels/test/index.php" , 3, "".ATTACHMENTS1."");
 
}
if(
$message == NULL){

if(
move_uploaded_file($_FILES['upload']['tmp_name'], $target))
{

$message =  "".ATTACHMENTS4."";

}
else
{
redirect_header(XOOPS_URL . "/modules/test/index.php" , 3, "".ATTACHMENTS3."");
}
}
echo 
$message;


include(
"../../footer.php");
?>

2
xsell
Re: Try to upload , Always message File not Allowed.
  • 2009/12/22 18:57

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


No worry .. Thank you to whoever Wrote this Snippet.

http://dev.xoops.org/modules/xfsnippet/detail.php?type=snippet&snippet_id=30