1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting "Undefined index: file"

Discussion in 'XenForo Development Discussions' started by Mr. Goodie2Shoes, May 15, 2012.

  1. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    so yes, the POST name is 'file' and here's a part of the admin template:
    Code:
    <xen:form action="{xen:adminlink 'downloads/upload/save'}" class="AutoValidator" data-redirect="on">
    
        <fieldset>
            <xen:selectunit name="subject" value="" label="Subject Code:">
                        <xen:options source="$subjectsOption" />
            </xen:selectunit>
            
            <xen:selectunit name="year" value="" label="Select Year:">
                        <xen:options source="$yearsOption" />
            </xen:selectunit>
            
            <xen:uploadunit label="Select Archive:" name="file" value=""></xen:uploadunit>
    
        
        </fieldset>
        
        <xen:submitunit save="Upload &amp; Save Archive">
        </xen:submitunit>
    
    </xen:form>
    and this is the part of the controller that processes the inputs:
    Code:
        public function actionUploadSave() {
            $pass = '~something~';
            $ch = curl_init('~something...~');
            $post_fields = "&pass=$pass";
            $post_fields .= "&file=".$_REQUEST['file'];
            $post_fields .= "&do=uploadarchive";
            $post_fields .= "&year=".$_REQUEST['year'];
            $post_fields .= "&subject=".$_REQUEST['subject'];
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_exec($ch);
            curl_close($ch);
            return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('downloads'));
        }
    and everything is working perfectly except this... and here's a pic of the error messsage:
    error.PNG

    P.S. This is under development and will go through loads of trials and errors, so don't worry any of the security flaws ;)
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Try this:

    Code:
    $post_fields .= "&file=".(isset($_REQUEST['file']) ? $_REQUEST['file'] : '');
    
    That's a standard method for handling possible nonexistent indexes.
     
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    yes, but I need the index called file, how else am I going to upload it? :p
    and why is this happening? since I have it in my form:
    Code:
    <xen:uploadunit label="Select Archive:" name="file" value=""></xen:uploadunit>
     
  4. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    still couldn't find a solution... help please? :(
     
  5. Naatan

    Naatan Well-Known Member

  6. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    I actually tried everything... $_POST, $_REQUEST and $_FILES... and XenForo's Upload Class: I have seen it but thats not exactly what I need as the files will be uploaded to a different server...
     
  7. Naatan

    Naatan Well-Known Member

    Try adding the following to your form tag:

    Code:
    enctype="multipart/form-data" method="POST"
     
  8. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Done that... no luck :(
     
  9. Naatan

    Naatan Well-Known Member

    Use your browsers developer tools to inspect the query being made, see if info is missing, mangled or simply named differently than you expected.
     
  10. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    How do I do that?
     
  11. Naatan

    Naatan Well-Known Member

  12. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    oh that... I use Firebug for the same purpose :D
    Lets see what I can find...
     

Share This Page