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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With