Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 Camera access & upload file using php

I am using below code for html 5 camera access and uploading the image to server.

HTML Code

<form action="upload.php" method="post" enctype="multipart/form-data">
  <input type="file" name="image" accept="image/*" capture>
  <input type="submit" value="Upload">
</form>

upload.php code

<?php 
$target_path = "upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

Problem is When I am testing the code it's showing "There was an error uploading the file, please try again!" . Can anyone help me to figure it out where the problem ?

Below code is working properly for me.

HTML Code :

<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

PHP code is same as above.

like image 733
Susim Samanta Avatar asked Feb 17 '13 11:02

Susim Samanta


People also ask

How do I embed a Webcam into my website?

First, you need to configure your camera or webcam to upload footage to CameraFTP.com. Then, log on to CameraFTP.com, select the camera in My Cameras page, click Publish. After you've published your camera, you can then copy and paste the Embed Code to your web page's HTML file.


1 Answers

IN the first case your file input name is named 'image' when on the second case is named 'uploadedfile'. Your PHP is expecting 'uploadedfile'.

To solve this you need to change your code (first case) to:

<form action="upload.php" method="post" enctype="multipart/form-data">  
   <input type="file" name="uploadedfile" accept="image/*" capture>  
   <input type="submit" value="Upload">  
</form>
like image 70
Thanasis Pap Avatar answered Oct 18 '22 01:10

Thanasis Pap