Getting "Undefined index: file"

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.webp

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

Code:
$post_fields .= "&file=".(isset($_REQUEST['file']) ? $_REQUEST['file'] : '');

That's a standard method for handling possible nonexistent indexes.
 
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>
 
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...
 
Try adding the following to your form tag:

Code:
enctype="multipart/form-data" method="POST"
 
Use your browsers developer tools to inspect the query being made, see if info is missing, mangled or simply named differently than you expected.
 
Top Bottom