Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

upload image file or take picture


bruyndoncx

Recommended Posts

 

In iPhone iOS6 and from Android ICS onwards, HTML5 has the following tag which allows you to take pictures from your device:

<input type="file" accept="image/*" capture="camera">

 

Capture can take values like camera, camcorder and audio.

 

 

 

So I added a new function tep_draw_media_field into admin/includes/functions/html_output.php

////
// Output a form filefield
  function tep_draw_file_field($name, $required = false) {
    $field = tep_draw_input_field($name, '', '', $required, 'file');

    return $field;
  }

////
// Output a form filefield for media input
  function tep_draw_media_field($name, $required = false) {
    $field = tep_draw_input_field($name, '', ' accept="image/*" capture="camera" ', $required, 'file');

    return $field;
  }
  

and instead fo the tep_draw_file_field in the script to upload an image file, you now replace the call with tep_draw_media_field

 

when accessing the webpage with a camera enabled device (phone, tablet) it will trigger the camera to take a picture, on regular pc, it will just show you the file dialog as before.

 

HTH

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

  • 1 month later...

one caveat - iphone/ipad seems to name everything "image.jpg" - so when uploading you have to decide how to name the file,

I added the productid so it becomes 1234_image.jpg

 

My image handling is custom, this is part of my solution in some common code that I call from different pages

 

		if ($products_image->parse()) {
			// to support ipad/iphone naming everything image.jpg
			$products_image_name = $products_image->filename;
			if ($products_image_name == 'image.jpg') {
				$products_image_name = $pid .'_'. $products_image_name;
				$products_image->set_filename($products_image_name);
			}
		}
next in code, $products_image->save() is called

 

I also have prepopulated from GET or POST depending on the page

$pid = (int) $_GET['pID'];

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...