Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HELP: Uploaded content is not recognized by PHP #713

Closed
salarmehr opened this issue May 2, 2015 · 5 comments
Closed

HELP: Uploaded content is not recognized by PHP #713

salarmehr opened this issue May 2, 2015 · 5 comments

Comments

@salarmehr
Copy link

I am trying to catch the uploaded file using $_FILES global array. While the content of file is sent to server, it seems PHP could not catch uploaded file meta-data (file name etc). So the $_FILES is empty. By the way, it's strange that I should set both file and data properties to file

    $scope.upload = function (files) {
        if (files != null && files[0]) {
            var file = files[0];
            console.log(file);

            file.upload = Upload.http({
                url: 'rest/file/',
                data:file,
                fileName:'test',
                file: file
            });

            file.upload.then(function (response) {
                file.result = response.data;
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            });

            file.upload.progress(function (evt) {
                file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
            });
        }
    }

HTML markup:

           <p>
                <label for="background">Background</label>
                <input ngf-select ngf-change="upload($files)" accept="image/*"
                       ng-model="form.background"
                       name="background" type="file"/>
                <img ng-show="form.background[0] != null" ngf-thumbnail="form.background[0]" class="thumb"/>
                        <span class="meter" ng-show="form.background[0].progress >= 0">
                                <span style="width:{{form.background[0].progress}}%"
                                      ng-bind="form.background[0].progress + '%'"
                                      class="ng-binding">
                                </span>
                        </span>

            </p>
@salarmehr salarmehr changed the title HELP: Uploaded content does not recognized by PHP HELP: Uploaded content is not recognized by PHP May 2, 2015
@danialfarid
Copy link
Owner

There is a wiki page for PHP, have you look at it?

@salarmehr
Copy link
Author

@danialfarid Yes, I have read it and tried it. It seems the issue is about the file name. It is not sent to server. It file contents is available using 'php://input however the $_FILE array is empty.

BTW: why both file and data are set to file in the PHP example.
Thanks.

@danialfarid
Copy link
Owner

I have updated the wiki, you don't need to set both or set the content-type.

@danialfarid
Copy link
Owner

Closing this, if you are still having issues please create a new one or reopen this.

@danialfarid
Copy link
Owner

#763
From version 5.0.0 instead of setting fileFormDataName you can set sendFieldsAs: "form"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants