0

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
  • 1
    There is no type="file" in your first snippet. Commented Jun 28, 2015 at 23:39

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.