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

Getting "Undefined index: file"

Mr. Goodie2Shoes

Well-known member
#1
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 ;)
 

Jake Bunce

XenForo moderator
Staff member
#2
Try this:

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

Mr. Goodie2Shoes

Well-known member
#3
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>
 

Mr. Goodie2Shoes

Well-known member
#6
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...
 

Naatan

Well-known member
#9
Use your browsers developer tools to inspect the query being made, see if info is missing, mangled or simply named differently than you expected.