0
votes

I have been researching for a while but all the solutions that I had find did not work

so It is super simple, I have this in view

                    <form method="POST" action="" enctype="multipart/form-data">
                    <input id="photoTarget" name="photoTarget" src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" type="image" style="width:400; height:300">
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <input type="submit" value="Upload" />
                </form>

I have also a script that takes a photo with your webcam and sets the attribute src of the input (type=image):

photo.setAttribute('src',picTemp.toDataURL('image/png'));

This works well, the input does get the image and u can see it load in the element, nothing fancy, so once the input got the source of the image, you click upload to send the request to laravel, in my controller's code I have this:

public function setPhoto(){

    $file = Request::file('photoTarget');
    var_dump($file);
}

I mean it can be more easy, but I always get null in the var_dump

Nothing seems to work

full controller code:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request;


use App\Http\Controllers\Controller;

class PatientController extends Controller
{

public function setPhoto(){

        $file = Request::file('photoTarget');
        var_dump($file);
    }

    public function getFicha(){
         return view('patient/ficha_medica');
    }
}

Thanks in advance

btw, when I use the

<input type="file" name="fileToUpload" id="fileToUpload">

and manually choose a file, it works, but the idea is to take a photo with the webcam

1
There is no type="file" in your first snippet.user2094178

1 Answers

1
votes

if you manage to get that image url into server after that this is the answer,(tip : write a java script function to set hidden input #photo_url value after you get image from webcam)

html form

    <form method="POST" action="" enctype="multipart/form-data">
    <input id="photoTarget" name="photoTarget"src="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg" type="image" style="width:400; height:300">
    <input type="hidden" id="photo_url" name="photo_url" value="http://www.vetprofessionals.com/catprofessional/images/home-cat.jpg">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <input type="submit" value="Upload" />
      </form>

your controller

$source = Input::get('image_url');
 $dest = "uploads/logo.png";
 copy($source, $dest);

file goes to here

public/uploads/logo.png

if you go permission denied error(if not don't do this)

sudo chmod -R 777 www-data:www-data "path to upload folder"
sudo chmod -R 777 "path to upload folder"