We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

moveTo is failing, cannot upload a file

I'm trying to uplaod a file, and move it to a folder that is not publicly accessible. I'm doing via an ajax uploader for some wiki code that we moved over to phalcon. I seem to get all the way to the upload, Chrome indicates that the file is uploading, but the return says the file was not uploaded. I'm hoping I just screwed up the permissions.

In my application folder, same dir level as the app folder, I have the target folder. Permissions are:

drwxrwxrwx 2 www-data www-data 12288 Apr 26 11:21 wikiFiles

My function:

public function upload_fileAction($wiki_word)
        #check if there is any file
        if( $this->request->hasFiles() == true )
            $uploads = $this->request->getUploadedFiles();
            $isUploaded = false;
            die( var_dump($uploads));
            #do a loop to handle each file individually
            foreach($uploads as $upload)
                $path = BASE_PATH . '/wikiFiles/' .  strtolower( $upload->getname() );

                #move the file and simultaneously check if everything was ok
                ( $upload->moveTo($path) ) ? $isUploaded = true : $isUploaded = false;

         #if any file couldn’t be moved, then throw an message
         ( $isUploaded ) ? '' : die( $path . ' ' . 'A file upload error ocurred.' );
            #if no files were sent, throw a message warning user
            die('You must choose at least one file to send. Please try again.');

        //Disable the view so it won't try to show a view for THIS Controller/Action

The response msg is: "/var/www/html/myApp/wikiFiles/testcapture.png A file upload error ocurred."

edited May '19

If it helps, this is what I get when I die and var_dump $this->request->getUploadedFiles() :

{responseText: "array(1) {↵  [0]=>↵  object(Phalcon\Http\Reques…nsion":protected]=>↵    string(3) "PNG"↵  }↵}↵", responseXML: document}responseText: "array(1) {↵  [0]=>↵  object(Phalcon\Http\Request\File)#52 (8) {↵    ["_name":protected]=>↵    string(15) "TestCapture.PNG"↵    ["_tmp":protected]=>↵    string(0) ""↵    ["_size":protected]=>↵    int(0)↵    ["_type":protected]=>↵    string(0) ""↵    ["_realType":protected]=>↵    NULL↵    ["_error":protected]=>↵    int(1)↵    ["_key":protected]=>↵    string(10) "userfile.0"↵    ["_extension":protected]=>↵    string(3) "PNG"↵  }↵}↵"responseXML: documentURL: "https://myapp.domain.com/wikiajax/upload_file/TestbyJeff"activeElement: bodyadoptedStyleSheets: []alinkColor: ""all: HTMLAllCollection(4) [html, head, style#stndz-style, body, stndz-style: style#stndz-style]anchors: HTMLCollection []applets: HTMLCollection []baseURI: "https://myapp.domain.com/wikiajax/upload_file/TestbyJeff"bgColor: ""body: bodycharacterSet: "UTF-8"charset: "UTF-8"childElementCount: 1childNodes: NodeList [html]children: HTMLCollection [html]compatMode: "BackCompat"contentType: "text/html"cookie: ""createElement: ƒ ()currentScript: nulldefaultView: nulldesignMode: "off"dir: ""doctype: nulldocumentElement: htmldocumentURI: "https://myapp.domain.com/wikiajax/upload_file/TestbyJeff"domain: "myapp.domain.com"embeds: HTMLCollection []featurePolicy: FeaturePolicy {}fgColor: ""firstChild: htmlfirstElementChild: htmlfonts: FontFaceSet {onloading: null, onloadingdone: null, onloadingerror: null, ready: undefined, status: "loaded", …}forms: HTMLCollection []fullscreen: falsefullscreenElement: nullfullscreenEnabled: falsehead: headhidden: trueimages: HTMLCollection []implementation: DOMImplementation {}inputEncoding: "UTF-8"isConnected: truelastChild: htmllastElementChild: htmllastModified: "05/30/2019 11:01:34"linkColor: ""links: HTMLCollection []location: nullnextSibling: nullnodeName: "#document"nodeType: 9nodeValue: nullonabort: nullonauxclick: nullonbeforecopy: nullonbeforecut: nullonbeforepaste: nullonblur: nulloncancel: nulloncanplay: nulloncanplaythrough: nullonchange: nullonclick: nullonclose: nulloncontextmenu: nulloncopy: nulloncuechange: nulloncut: nullondblclick: nullondrag: nullondragend: nullondragenter: nullondragleave: nullondragover: nullondragstart: nullondrop: nullondurationchange: nullonemptied: nullonended: nullonerror: nullonfocus: nullonfreeze: nullonfullscreenchange: nullonfullscreenerror: nullongotpointercapture: nulloninput: nulloninvalid: nullonkeydown: nullonkeypress: nullonkeyup: nullonload: nullonloadeddata: nullonloadedmetadata: nullonloadstart: nullonlostpointercapture: nullonmousedown: nullonmouseenter: nullonmouseleave: nullonmousemove: nullonmouseout: nullonmouseover: nullonmouseup: nullonmousewheel: nullonpaste: nullonpause: nullonplay: nullonplaying: nullonpointercancel: nullonpointerdown: nullonpointerenter: nullonpointerleave: nullonpointerlockchange: nullonpointerlockerror: nullonpointermove: nullonpointerout: nullonpointerover: nullonpointerup: nullonprogress: nullonratechange: nullonreadystatechange: nullonreset: nullonresize: nullonresume: nullonscroll: nullonsearch: nullonseeked: nullonseeking: nullonselect: nullonselectionchange: nullonselectstart: nullonstalled: nullonsubmit: nullonsuspend: nullontimeupdate: nullontoggle: nullonvisibilitychange: nullonvolumechange: nullonwaiting: nullonwebkitfullscreenchange: nullonwebkitfullscreenerror: nullonwheel: nullownerDocument: nullparentElement: nullparentNode: nullpictureInPictureElement: nullpictureInPictureEnabled: falseplugins: HTMLCollection []pointerLockElement: nullpreviousSibling: nullreadyState: "complete"referrer: ""rootElement: nullscripts: HTMLCollection []scrollingElement: bodystyleSheets: StyleSheetList {0: CSSStyleSheet, length: 1}textContent: nulltitle: ""visibilityState: "hidden"vlinkColor: ""wasDiscarded: falsewebkitCurrentFullScreenElement: nullwebkitFullscreenElement: nullwebkitFullscreenEnabled: falsewebkitHidden: truewebkitIsFullScreen: falsewebkitVisibilityState: "hidden"xmlEncoding: nullxmlStandalone: falsexmlVersion: null__proto__: HTMLDocument__proto__: Object


I'm a fool. It was a file size limit issue.

I'm a fool. It was a file size limit issue.

Welcome to the club :D