Неопределенный индекс: ошибка файла на виртуальном хостинге HOSTINGER - PullRequest
0 голосов
/ 06 октября 2019

У меня есть код для загрузки файла. Это работает на моем локальном хосте с IP-адресом. Но это не работает на виртуальном хостинге, который является Hostinger. Это показывает ниже ошибку. Пожалуйста помоги.

Неопределенный индекс: файл {"исключение": "[объект] (ErrorException (код: 0): Неопределенный индекс: файл в /home/u766753775/domains/nammoor.online/public_html/laravel/маршруты / 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); });
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...