Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70791

Undefined index:file , while uploading the image from ionic file transfer to PHp server

$
0
0

@Velmurugan wrote:

I have below code for file upload. This is working in my localhost with the IP address. But it’s not working in shared hosting that is Hostinger. It’s showing below error. Please help.

Undefined index: file {“exception”:"[object] (ErrorException(code: 0): Undefined index: file at /home/u766753775/domains/nammoor.online/public_html/laravel/routes/web.php:527)

IONIC 4:

    async CameraImageUploadwithoutCrop() {
      await this.imagePicker.getPictures({ maximumImagesCount: 1, outputType: 0 }).then((results) => {
        for (const image of results) {
            console.log('Image URI: ' + image);
            const fileTransfer: FileTransferObject = this.transfer.create();
            const uploadOpts: FileUploadOptions = {
                fileKey: 'file',
                fileName: image.substr(image.lastIndexOf('/') + 1)
            };
    
            fileTransfer.upload(image, 'https://nammoor.online/post/uploadImage', uploadOpts)
            // fileTransfer.upload(image, 'http://191.168.01.10:8000/post/uploadImage', uploadOpts)
              .then((data) => {
                console.log(data);
                this.respData = JSON.parse(data.response);
                console.log(this.respData);
                this.imageUrl = this.respData.fileUrl;
              }, (err) => {
                console.log(err);
              });
    
        }
      }, (err) => { console.log(err); });
    }

PHP:

          Route::post('/post/uploadImage', function (Request $request) {
    
      // Route::post('image-upload', )->name('image.upload.post');
      $connection = OpenCon();
      $request = Request::instance(); // Access the instance
      $content = $request->getContent(); // Get its content
      // p($request);
    
    $date = date('dmYHis');
    $target_path = "uploads/images/".$date.".jpg";
    
        try {
          //if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
          if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
        
            //$fileUrl = "http://191.168.01.10:8000/".$target_path."";
            $fileUrl = "https://nammoor.online/".$target_path."";
        
            $eRes = json_encode('{ "fileUrl": "'.$fileUrl.'"}', true);
            p($fileUrl);
            $msg = json_decode($eRes ,true);
            p($msg);
            return $msg;
          } else {
          echo $target_path;
          }	
            }
          }, (err) => { console.log(err); });
        }

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70791

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>