Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[CONTRIBUTION] File uploads as an Option Feature


Guest

Recommended Posts

Can anyone PLEASE help i have followed the install info and i am getting this error when i try and upload an image

 

Error: destination does not exist.

 

this error is on the product page.

 

I am running my sql 4.1

 

Thanks in advance

 

Andy

Link to comment
Share on other sites

  • Replies 482
  • Created
  • Last Reply

Top Posters In This Topic

Ok i am not getting the error now i changed the image/upload.php file permissions to 777 now the problem is its trying to upload the image but its not actually uploading it and the checkout isn't show it but i guess that's because its not actually uploaded to images/upload.php.

 

Can someone please point me in the right direction

 

Thank you

 

Andy

Link to comment
Share on other sites

Ok i am not getting the error now i changed the image/upload.php file permissions to 777 now the problem is its trying to upload the image but its not actually uploading it and the checkout isn't show it but i guess that's because its not actually uploaded to images/upload.php.

 

Can someone please point me in the right direction

 

Thank you

 

Andy

 

May be a stupid question, but did you upload all the NEW files too? (not just the changed ones? --> Thinking of upload.php)

I'm still working on adding another contrib, and will have a crack at this one soon, so I hope I can then assist you better...

Like Eek said... It never hurts to help!
----------------------------------------

Link to comment
Share on other sites

Thank you Zappo for your reply

 

Yeah i have checked all files have been uploaded checked database, its going to be something simple i guess unfortunately the oscommerce software and php is really new to me.

 

Cant wait Zappo thank you so much.

Link to comment
Share on other sites

I already have Option Type Feature 1.7.2 installed. I'd like to add the ability to upload a picture as well - can I do that using this module, or is there a better alternative given what I already have set up?

Link to comment
Share on other sites

Ok i believe its something easy i have missed when i try and upload a file/ image it is trying because i have tried to upload to different sized files 1 small 1 large and the large file takes awhile to try and upload, but its not uploading the file to the images/upload folder.

 

I feel i am so close i think its just getting the image/file to be copied into the folder (images/upload) and then it would be displayed on the checkout with the order.

 

If you think i have missed something out please Shout because i need to get this sorted so i can start selling printed products

Link to comment
Share on other sites

Can anyone please help me

 

I have installed the upload.77 i have installed this from fresh several times now and i still cant get it to work every time when on a product i select an image to be uploaded and it just wont upload and no file name is displayed in cart but i guess thats because theres no image uploaded. I am not getting any errors on any part of my site.

 

Please Please help me my web site is parakeetprint .co .uk

 

Thanks

Link to comment
Share on other sites

Hi, I'm very new to OScommerce, php, web hosting, you name it. :blink:

 

but so far I've managed to get my site working pretty well. I need to have the option for a customer to upload files, possibly up to 6 per product. will this option allow that or does this only allow for 1 file to be uploaded per product?

 

also, does this work with MySQL 5? I think some of the replies I saw a few posts back were showing changes needed to make this work in mysql5 but I want to verify before I start mucking with things since I'm not super comfortable with any changes I'm making right now. looks like I'm running php4.

 

thanks so much for any input!!!

Link to comment
Share on other sites

Hi, I'm very new to OScommerce, php, web hosting, you name it. :blink:

 

but so far I've managed to get my site working pretty well. I need to have the option for a customer to upload files, possibly up to 6 per product. will this option allow that or does this only allow for 1 file to be uploaded per product?

 

also, does this work with MySQL 5? I think some of the replies I saw a few posts back were showing changes needed to make this work in mysql5 but I want to verify before I start mucking with things since I'm not super comfortable with any changes I'm making right now. looks like I'm running php4.

 

thanks so much for any input!!!

 

 

Ok, I read thru this whole thread (I should have read before posting), but now I have more specific questions to ask:

 

1. will this work with mysql5?

2. can this work with the quantity price break contrib? i need both options. neither are installed so if there is a recommended order to install them *IF* they do work together I would love to hear any tips/cautions.

 

It looks like the original contributor is no longer active in this thread so hopefully someone else has used this and will know the answers!!! thanks for your time!!!

Link to comment
Share on other sites

I have this mod installed, and it works great - except one thing. When the customers chooses to pay with PayPal, all the extra order-info is lost. I can't see which image they've chosen or the text-fields.

 

Anyone else experienced this? :blink:

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

 

Need a BIG FAVOUR PLEASE!!! :) Can someone update this so it will work with Mysql 5. I really need this mod for my customers to upload there photos.

 

I cant do it as I have no idea when it comes to writing php.

 

Please someone, pretty please.

 

Thanks

Link to comment
Share on other sites

I already had Option Type Feature 1.7.2 installed, and needed file upload capability, but this module appears to be fairly old and not built on the current release of OSCommerce (?) - in any case, I used it as a guide and modified my setup to get file uploading working. I have a bunch of extra modules installed so not 100% sure this will work for a vanilla install with OTF 1.7.2, but I didn't see anything that appeared to be related to one of my other changes in the relevant sections.

 

This feature should probably be rolled into OTF anyway. I hope this is useful to someone. Here's my code.

 

-------------------------------

Modified files:
product_info.php
admin/products_attributes.php
includes/application_top.php
includes/configure.php
includes/database_tables.php
includes/functions/html_output.php
includes/languages/english.php

New file:
includes/classes/upload.php


###################################################################
SQL to create files_uploaded table
===================================================================
CREATE TABLE `files_uploaded` (
`files_uploaded_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`sesskey` VARCHAR( 32 ) ,
`customers_id` INT( 11 ) ,
`files_uploaded_name` VARCHAR( 64 ) NOT NULL ,
PRIMARY KEY ( `files_uploaded_id` ) 
) COMMENT = 'Must always have either a sesskey or customers_id';
###################################################################

###################################################################
product_info.php
===================================================================
### FIND

	  <p><?php echo stripslashes($product_info['products_description']); ?></p>
<?php

### ADD AFTER

$number_of_uploads = 0;

===================================================================
### FIND

	  case PRODUCTS_OPTIONS_TYPE_TEXTAREA:

### ADD BEFORE

	  case PRODUCTS_OPTIONS_TYPE_FILE:
		//CLR 030714 Add logic for text option
		$number_of_uploads++;
		$products_attribs_query = tep_db_query("select distinct patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");
		$products_attribs_array = tep_db_fetch_array($products_attribs_query);

	   $tmp_html = '<input type="file" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] .  ']" size="' . $products_options_name['products_options_length'] .'">';

		if ($products_attribs_array['options_values_price'] != '0') {
		  $tmp_html .= '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .')';
		}
?>
		<tr>
		  <td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
<!--			  <td class="main"><?php echo $tmp_html;  ?></td> -->

	<td class="main"><input type="file" name="id[<?php echo TEXT_PREFIX . $products_options_name['products_options_id']; ?>]"><br>
<?php echo $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . tep_draw_hidden_field(UPLOAD_PREFIX . $number_of_uploads, $products_options_name['products_options_id']) . tep_draw_hidden_field(TEXT_PREFIX . UPLOAD_PREFIX . $number_of_uploads, $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']]); ?></td>


		</tr>
<?php
		break;

===================================================================
### FIND

</table></form></td>

### ADD BEFORE

  <tr>
	<td><?php echo tep_draw_hidden_field('number_of_uploads', $number_of_uploads); ?></td>
  </tr>

###################################################################

###################################################################
admin/products_attributes.php
===================================================================
### FIND

 $values[] = array('id' => 4, 'text' => 'Textarea');

### ADD AFTER

 $values[] = array('id' => 5, 'text' => 'File');

===================================================================
### FIND

 if ($opt_type == 4) return 'Textarea';

### ADD AFTER

 if ($opt_type == 5) return 'File';

###################################################################

###################################################################
includes/application_top.php
===================================================================
### FIND

 $navigation->add_current_page();

### ADD AFTER

// infobox
 require(DIR_WS_CLASSES . 'boxes.php');

// initialize the message stack for output messages
 require(DIR_WS_CLASSES . 'message_stack.php');
 $messageStack = new messageStack;

===================================================================
### FIND

  // customer adds a product from the products page
  case 'add_product' :	if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
							$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;

### REPLACE WITH

  // customer adds a product from the products page
  case 'add_product' :	if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
	  $real_ids = $HTTP_POST_VARS['id'];
	  if ($HTTP_POST_VARS['number_of_uploads'] > 0) {
		require(DIR_WS_CLASSES . 'upload.php');
   for ($i = 1; $i <= $HTTP_POST_VARS['number_of_uploads']; $i++) {
	 if (tep_not_null($_FILES['id']['tmp_name'][TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i]]) and
		 ($_FILES['id']['tmp_name'][TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i]] != 'none')) {
	   $products_options_file = new upload('id');
	   $products_options_file->set_destination(DIR_FS_UPLOADS);

	   if ($products_options_file->parse(TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i])) {
		 if (tep_session_is_registered('customer_id')) {
		   tep_db_query("insert into " . TABLE_FILES_UPLOADED . " (sesskey, customers_id, files_uploaded_name) values('" .
						tep_session_id() . "', '" . $customer_id . "', '" .
						tep_db_input($products_options_file->filename) . "')");
		 } else {
				tep_db_query("insert into " . TABLE_FILES_UPLOADED . " (sesskey, files_uploaded_name) values('" .
							 tep_session_id() . "', '" . tep_db_input($products_options_file->filename) . "')");
			  }
			  $insert_id = tep_db_insert_id();
			  $real_ids[TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i]] = $insert_id . "_" .
																			 $products_options_file->filename;
			  $products_options_file->set_filename("$insert_id");
			  if (!($products_options_file->save())) {
				break 2;
			  }
			} else {
			  break 2;
			}
		  } else { // No file uploaded -- use previous value
			$real_ids[TEXT_PREFIX . $HTTP_POST_VARS[UPLOAD_PREFIX . $i]] = $HTTP_POST_VARS[TEXT_PREFIX . UPLOAD_PREFIX . $i];
		  }
		}
	  }
	  $cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $real_ids))+1, $real_ids);
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;

===================================================================
### FIND (towards the bottom of the file, not the one entered above)

 require(DIR_WS_CLASSES . 'boxes.php');

### REPLACE WITH

//  require(DIR_WS_CLASSES . 'boxes.php');

===================================================================
### FIND (towards the bottom of the file, not the one entered above)

 require(DIR_WS_CLASSES . 'message_stack.php');
 $messageStack = new messageStack;

### REPLACE WITH

//  require(DIR_WS_CLASSES . 'message_stack.php');
//  $messageStack = new messageStack;

###################################################################

###################################################################
includes/configure.php
===================================================================
### FIND

 define('PRODUCTS_OPTIONS_TYPE_TEXTAREA', 4);

### ADD AFTER

 define('PRODUCTS_OPTIONS_TYPE_FILE', 5);
 define('UPLOAD_PREFIX', 'upl_');
 define('DIR_FS_UPLOADS', 'REPLACE WITH FULL PATH TO UPLOAD DIRECTORY');

###################################################################

###################################################################
includes/database_tables.php
===================================================================
### ADD BEFORE CLOSING ?>

 define('TABLE_FILES_UPLOADED', 'files_uploaded');

###################################################################

###################################################################
includes/functions/html_output.php
===================================================================
### FIND

$form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';

### REPLACE WITH

$form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '" enctype="multipart/form-data"';

###################################################################

###################################################################
includes/languages/english.php
===================================================================
### ADD BEFORE CLOSING ?>

define('ERROR_FILETYPE_NOT_ALLOWED', 'Error:  File type not allowed.');
define('WARNING_NO_FILE_UPLOADED', 'Warning:  no file uploaded.');
define('SUCCESS_FILE_SAVED_SUCCESSFULLY', 'Success:  file saved successfully.');
define('ERROR_FILE_NOT_SAVED', 'Error:  file not saved.');
define('ERROR_DESTINATION_NOT_WRITEABLE', 'Error:  destination not writeable.');
define('ERROR_DESTINATION_DOES_NOT_EXIST', 'Error: destination does not exist.');

###################################################################

###################################################################
NEW FILE: includes/classes/upload.php
===================================================================
<?php
/*
 $Id: upload.php,v 1.2 2003/06/20 00:18:30 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class upload {
var $file, $filename, $destination, $permissions, $extensions, $tmp_filename, $message_location;

function upload($file = '', $destination = '', $permissions = '777', $extensions = '') {
  $this->set_file($file);
  $this->set_destination($destination);
  $this->set_permissions($permissions);
  $this->set_extensions($extensions);

  $this->set_output_messages('direct');

  if (tep_not_null($this->file) && tep_not_null($this->destination)) {
	$this->set_output_messages('session');

	if ( ($this->parse() == true) && ($this->save() == true) ) {
	  return true;
	} else {
	  return false;
	}
  }
}

function parse($key = '') {
  global $messageStack;

	$file = array('name' => $_FILES[$this->file]['name'][$key],
				  'type' => $_FILES[$this->file]['type'][$key],
				  'size' => $_FILES[$this->file]['size'][$key],
				  'tmp_name' => $_FILES[$this->file]['tmp_name'][$key]);


  if ( tep_not_null($file['tmp_name']) && ($file['tmp_name'] != 'none') ) {
	if (sizeof($this->extensions) > 0) {
	  if (!in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions)) {
		if ($this->message_location == 'direct') {
		  $messageStack->add(ERROR_FILETYPE_NOT_ALLOWED, 'error');
		} else {
		  $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
		}

		return false;
	  }
	}

	$this->set_file($file);
	$this->set_filename($file['name']);
	$this->set_tmp_filename($file['tmp_name']);

	return $this->check_destination();
  } else {
	if ($this->message_location == 'direct') {
	  $messageStack->add(WARNING_NO_FILE_UPLOADED, 'warning');
	} else {
	  $messageStack->add_session(WARNING_NO_FILE_UPLOADED, 'warning');
	}

	return false;
  }
}

function save() {
  global $messageStack;

  if (substr($this->destination, -1) != '/') $this->destination .= '/';

  if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename . "_" . $this->file['name'])) {
	chmod($this->destination . $this->filename, $this->permissions);

	if ($this->message_location == 'direct') {
	  $messageStack->add(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
	} else {
	  $messageStack->add_session(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
	}

	return true;
  } else {
	if ($this->message_location == 'direct') {
	  $messageStack->add(ERROR_FILE_NOT_SAVED, 'error');
	} else {
	  $messageStack->add_session(ERROR_FILE_NOT_SAVED, 'error');
	}

	return false;
  }
}

function set_file($file) {
  $this->file = $file;
}

function set_destination($destination) {
  $this->destination = $destination;
}

function set_permissions($permissions) {
  $this->permissions = octdec($permissions);
}

function set_filename($filename) {
  $this->filename = $filename;
}

function set_tmp_filename($filename) {
  $this->tmp_filename = $filename;
}

function set_extensions($extensions) {
  if (tep_not_null($extensions)) {
	if (is_array($extensions)) {
	  $this->extensions = $extensions;
	} else {
	  $this->extensions = array($extensions);
	}
  } else {
	$this->extensions = array();
  }
}

function check_destination() {
  global $messageStack;

  if (!is_writeable($this->destination)) {
	if (is_dir($this->destination)) {
	  if ($this->message_location == 'direct') {
		$messageStack->add(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error');
	  } else {
		$messageStack->add_session(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error');
	  }
	} else {
	  if ($this->message_location == 'direct') {
		$messageStack->add(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error');
	  } else {
		$messageStack->add_session(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error');
	  }
	}

	return false;
  } else {
	return true;
  }
}

function set_output_messages($location) {
  switch ($location) {
	case 'session':
	  $this->message_location = 'session';
	  break;
	case 'direct':
	default:
	  $this->message_location = 'direct';
	  break;
  }
}
 }
?>

Link to comment
Share on other sites

Hello All, First let me say this is a solid contribution and has served very well. Second, my php skills are pretty weak. I was just wondering if anyone has gone so far as to extend it's use to the admin side beyond a link to the image. Customers can currently upload an image without problems and I have been using Order Editor to Add a Proof "product" to orders and uploading the proof by ftp.

 

It would be nice to be able to add a file upload to the orders.php to simplify the process. If anyone has done so I'd be appreciative to hear the details.

 

If I hear nothing and have any success I will post the results.

 

Thanks!

Link to comment
Share on other sites

This contribution does not work for everyone. Before adding little extras to this contribution, I think it would serve everyone better if it could be updated first. If someone could be kind enough to do so, it would be much appreciated :)

Link to comment
Share on other sites

First please take a look at what I'm trying to do with product attributes at my test site. Ok, so I need to charge customers the wordcount multiplied by the turnaround time. For example, if the turnaround time of 12 hours is selected, it's value might be $0.10. Then the wordcount selected might be 500. I need these two values to be multiplied to get at a final price of $50.00. Any ideas? I'm totally stumped. I tried using a standard quantity field for the wordcount, but I can't get it to work after installing this contribution. Thanks in advance! B)

Link to comment
Share on other sites

First please take a look at what I'm trying to do with product attributes at my test site. Ok, so I need to charge customers the wordcount multiplied by the turnaround time. For example, if the turnaround time of 12 hours is selected, it's value might be $0.10. Then the wordcount selected might be 500. I need these two values to be multiplied to get at a final price of $50.00. Any ideas? I'm totally stumped. I tried using a standard quantity field for the wordcount, but I can't get it to work after installing this contribution. Thanks in advance! B)

I figured out how to get the quantity to work on the product_info.php page with this contribution. I don't know is anyone else is having this problem, but just in case here is the solution.

Link to comment
Share on other sites

  • 2 months later...

Is this contribution still valid and working? There are conflicting statements near the top on whether it works with MYSQL 5.

 

I tried installing it and am not seeing that it is working. I wish to have a customer upload a photograph and then basically select a size to have it printed, or vice verse (select a size and then upload a photo).

 

Anyway, I am not seeing success on my first attempt even though I believe I followed the directions.

 

Is this a correct result on import of this file?

 

MySQL returned an empty result set (i.e. zero rows). (Query took 0.0052 sec)
SQL query:
CREATE TABLE `files_uploaded` (
`files_uploaded_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`sesskey` VARCHAR( 32 ) ,
`customers_id` INT( 11 ) ,
`files_uploaded_name` VARCHAR( 64 ) NOT NULL ,
PRIMARY KEY ( `files_uploaded_id` )
) COMMENT = 'Must always have either a sesskey or customers_id';

Link to comment
Share on other sites

Is this contribution still valid and working as of osCommerce Online Merchant v2.2 Release Candidate 1? There are conflicting statements near the top on whether it works with MYSQL 5. ... would not let me edit sorry.

 

sorry would not let me edit my own reply

Link to comment
Share on other sites

  • 2 weeks later...

Hows it going Matt,

 

I recently installed your contrib, and it is definitely a life saver, the only problem I am having ( which I didnt see in anyones posts from page 1-15)

 

I can get it working the way it should, but it makes the products on my site display all wrong,

 

I dont know much about coding, but Ive spent hours trying to get this fixed.

 

Any help would be great.

 

The site is :

 

http://thesneakerbox.net/store

 

 

Thanks in advance!

 

Ian

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...