mercredi 9 septembre 2020

How to debug contents File Upload in PHP?

Description

I have a form, that I used to upload .yaml file that contain these

nsd: 
  name: F-FortiGate
  description: F FortiGate KVM64
  vendor: Benu
  version: '1.0'
  constituent-vnfd:
    member-vnf-id1: fortiGate

As soon as I upload, and capture the packet, I see that the content getting malformed to look something like this

--------------------------c861a90dcb2a5d6c
Content-Disposition: form-data; name="file"


@
--------------------------c861a90dcb2a5d6c--

Wireshark also showing it

enter image description here

View

{!! Form::open(array('url' => '/ns-descriptors/store', 'role' =>'form','id' => 'editFavicon','files'=>true, 'enctype'=>'multipart/form-data')) !!}

<p>
    <input id="file" name="file" type="file" class="filestyle" data-iconName="fa fa-plus">
</p>



<div class="modal-footer">
    <a href="/ns-descriptors" class="btn btn-default">Cancel</a>
    <button type="submit" class="btn btn-success">Save</button>
</div>


{!! Form::close();!!}

Controller

if (Input::hasFile('file')){

$file                = Input::file('file');
$filename            = $file->getClientOriginalName();

dd($file);

if ( strpos($filename, '-nsd-') !== false) {

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, env('ACS_URL').'/files/'.$filename);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $post = array(
        'file' => '@' .realpath('\"./'.$filename.'\"')
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

    $headers = array();
    $headers[] = 'filetype: 3 Vendor Configuration File';
    $headers[] = 'oui: Benu';
    $headers[] = 'productClass: xMEG-1';
    $headers[] = 'version: 2.0';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);


}

I got

Illuminate\Http\UploadedFile {#1388 ▼
  -test: false
  -originalName: "config-nsd-Xorcom-PBX.yaml"
  -mimeType: "application/x-yaml"
  -error: 0
  #hashName: null
  path: "/private/var/tmp"
  filename: "phpoxjiAe"
  basename: "phpoxjiAe"
  pathname: "/private/var/tmp/phpoxjiAe"
  extension: ""
  realPath: "/private/var/tmp/phpoxjiAe"
  aTime: 2020-09-09 12:46:11
  mTime: 2020-09-09 12:46:11
  cTime: 2020-09-09 12:46:11
  inode: 45802602
  size: 140
  perms: 0100600
  owner: 70
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}

I want to debug and see what the content of my .yaml file.

How would I do that?

Why does my form submit malformed contents? How do I prevent that ? 😔



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire