PIMCORE Uploading file

Uploading Files using Pimcore:-

For uploading file on pimcore we primarily need two things-

  1. we must have a folder inside the assets
  2. we must have a class to store file object with a folder in assets to save the file.

Suppose we are uploading some pdf files via pimcore, we must have a folder under Assets section and a folder under Objects section. The file will be uploaded inside asset’s folder and a new object will be create under object section. Any time admin can check the list of uploaded file via objects.

Here we are uploading resumes with user’s name, email, phone number. As we have seen in folder structure of Pimcore the file will be moved into assets and a new object will be created into object Section.

    $folder = "/resumes";
    $parentId = Asset::getByPath($folder)->getId();
    $filename = strtolower(time().$_FILES['file_source']['name']);
    $data = file_get_contents($_FILES['file_source']['tmp_name']);
    $asset = Asset::create(
        $parentId,  //Parent ID
            "filename" => $filename,
            "data" => $data,
            "userOwner" => 1,
            "userModification" => 1
    $userdata = [
        "Name" => $name,
        "Email" => $email,
        "Phone" => $phone,
        "Resume" => $folder.$filename

    $objJobRequest = Object_JobRequest::create($userdata);
    $object = Object_Abstract::getByPath($folder);
    $response = $objJobRequest->save();

Here we are checking if the method of request is post. only post methods are allowed for uploading a file.
If request is valid then we will create a new asset and move it inside the resume folders in assets Section. After that a new object will be create and it will be inside the resume’s folder in objects Section.

Note:- We must have to set a parent id (which is the folder path in object section), a unique key to abject, And Published flag to false so that first admin have to review it and valid values will be published only.