473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Http post fields ...

Hi,

I'm trying to add an simple upload applet to shopping cart script. My new
applet form sends all needed post fields ( quantity, product, etc... )
but the "file" post field is hardcoded in applet.
Shop script works with :
<input type="file" name="id[SourceFile_1]"/>
but not with applet's:
<input type="file" name="SourceFile_1"/>
I just cannot figure out how to fix this :(
Could somebody please help me?

Thanks in advanced,

-Event

Upload function:
################################################## ################

function actionUploadPhotos($goto, $parameters, $message=false) {
global $messageStack, $db;
if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
$the_list = '';
$adjust_max= 'false';
if (isset($_POST['id'])) {
foreach ($_POST['id'] as $key =$value) {
$check = zen_get_attributes_valid($_POST['products_id'], $key,
$value);
if ($check == false) {
$the_list .= TEXT_ERROR_OPTION_FOR . '<span class="alertBlack">'
.. zen_options_name($key) . '</span>' . TEXT_INVALID_SELECTION . '<span
class="alertBlack">' . (zen_values_name($value) == 'TEXT' ?
TEXT_INVALID_USER_INPUT : zen_values_name($value)) . '</span>' . '<br />';
}
}
}
$add_max = zen_get_products_quantity_order_max($_POST['products_id']);
$cart_qty = $this->in_cart_mixed($_POST['products_id']);
$new_qty = $_POST['cart_quantity'];
//echo 'I SEE actionUploadPhotos: ' . $_POST['products_id'] . '<br>';
$new_qty = $this->adjust_quantity($new_qty, $_POST['products_id'],
'shopping_cart');
if (($add_max == 1 and $cart_qty == 1)) {
// do not add
$new_qty = 0;
$adjust_max= 'true';
} else {
// adjust quantity if needed
if (($new_qty + $cart_qty $add_max) and $add_max != 0) {
$adjust_max= 'true';
$new_qty = $add_max - $cart_qty;
}
}
if ((zen_get_products_quantity_order_max($_POST['products_id']) == 1
and $this->in_cart_mixed($_POST['products_id']) == 1)) {
} else {

if ($the_list != '') {
$messageStack->add('product_info', ERROR_CORRECTIONS_HEADING .
$the_list, 'caution');
} else {
$real_ids = isset($_POST['id']) ? $_POST['id'] : "";
if (isset($_GET['number_of_uploads']) &&
$_GET['number_of_uploads'] 0) {
/**
* Need the upload class for attribute type that allows uploads.
*
*/
include(DIR_WS_CLASSES . 'upload2.php');
for ($i = 1, $n = $_GET['number_of_uploads']; $i <= $n; $i++) {
if
(zen_not_null($_FILES['SourceFile_1']['tmp_name'][TEXT_PREFIX .
$_POST[UPLOAD_PREFIX . $i]]) and
($_FILES['SourceFile_1']['tmp_name'][TEXT_PREFIX . $_POST[UPLOAD_PREFIX .
$i]] != 'none')) {
$products_options_file = new upload('id');
$products_options_file->set_destination(DIR_FS_UPLOADS);
$products_options_file->set_output_messages('session');
if ($products_options_file->parse(TEXT_PREFIX .
$_POST[UPLOAD_PREFIX . $i])) {
$products_image_extension =
substr($products_options_file->filename,
strrpos($products_options_file->filename, '.'));

if ($_SESSION['customer_id']) {
$db->Execute("insert into " . TABLE_FILES_UPLOADED . "
(sesskey, customers_id, files_uploaded_name) values('" . zen_session_id() .
"', '" . $_SESSION['customer_id'] . "', '" .
zen_db_input($products_options_file->filename) . "')");
} else {
$db->Execute("insert into " . TABLE_FILES_UPLOADED . "
(sesskey, files_uploaded_name) values('" . zen_session_id() . "', '" .
zen_db_input($products_options_file->filename) . "')");
}
$insert_id = $db->Insert_ID();
$real_ids[TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] =
$insert_id . ". " . $products_options_file->filename;
$products_options_file->set_filename("$insert_id" .
$products_image_extension);
if (!($products_options_file->save())) {
break;
}
} else {
break;
}
} else { // No file uploaded -- use previous value
$real_ids[TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] =
$_POST[TEXT_PREFIX . UPLOAD_PREFIX . $i];
}
}
}

$this->add_cart($_POST['products_id'],
$this->get_quantity(zen_get_uprid($_POST['products_id'],
$real_ids))+($new_qty), $real_ids);
// iii 030813 end of changes.
} // eof: set error message
} // eof: quantity maximum = 1

if ($adjust_max == 'true') {
$messageStack->add_session('shopping_cart', ERROR_MAXIMUM_QTY . '
B: - ' . zen_get_products_name($_POST['products_id']), 'caution');
}
}
if ($the_list == '') {
if (DISPLAY_CART == 'false' && $_GET['main_page'] !=
FILENAME_SHOPPING_CART) {
$messageStack->add_session('header', SUCCESS_ADDED_TO_CART_PRODUCT,
'success');
}
zen_redirect(zen_href_link($goto,
zen_get_all_get_params($parameters)));
} else {
}
}

################################################## ##################################################
in upload2.php ( parse function and save )

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

if (isset($_FILES[$this->file])) {
if (zen_not_null($key)) {
$file = array('name' =$_FILES[$this->file]['name'][$key],
'type' =$_FILES[$this->file]['type'][$key],
'size' =$_FILES[$this->file]['size'][$key],
'tmp_name' =$_FILES['file']['tmp_name']);
} else {
$file = array('name' =$_FILES[$this->file]['name'],
'type' =$_FILES[$this->file]['type'],
'size' =$_FILES[$this->file]['size'],
'tmp_name' =$_FILES['file']['tmp_name']);
}
} elseif (isset($GLOBALS['HTTP_POST_FILES'][$this->file])) {
global $HTTP_POST_FILES;

$file = array('name' =$HTTP_POST_FILES[$this->file]['name'],
'type' =$HTTP_POST_FILES[$this->file]['type'],
'size' =$HTTP_POST_FILES[$this->file]['size'],
'tmp_name' =$HTTP_POST_FILES[$this->file]['tmp_name']);
} else {
$file = array('name' =(isset($GLOBALS[$this->file . '_name']) ?
$GLOBALS[$this->file . '_name'] : ''),
'type' =(isset($GLOBALS[$this->file . '_type']) ?
$GLOBALS[$this->file . '_type'] : ''),
'size' =(isset($GLOBALS[$this->file . '_size']) ?
$GLOBALS[$this->file . '_size'] : ''),
'tmp_name' =(isset($GLOBALS[$this->file]) ? $GLOBALS[$this->file] :
''));
}
if (!is_uploaded_file($_FILES['tmp_name'])) {
if ($this->message_location == 'direct') {
$messageStack->add_session('header', WARNING_NO_FILE_UPLOADED,
'warning');
} else {
$messageStack->add_session('upload', WARNING_NO_FILE_UPLOADED,
'warning');
}
return false;
}

if ( zen_not_null($file['tmp_name']) && ($file['tmp_name'] != 'none') &&
is_uploaded_file($file['tmp_name']) ) {
if (zen_not_null($file['size']) and ($file['size'] >
MAX_FILE_UPLOAD_SIZE)) {
if ($this->message_location == 'direct') {
$messageStack->add_session('header', ERROR_FILE_TOO_BIG, 'error');
} else {
$messageStack->add_session('upload', ERROR_FILE_TOO_BIG, 'error');
}
return false;
}

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_session('header', ERROR_FILETYPE_NOT_ALLOWED
.. ' ' . UPLOAD_FILENAME_EXTENSIONS, 'error');
} else {
$messageStack->add_session('upload', ERROR_FILETYPE_NOT_ALLOWED
.. ' - ' . UPLOAD_FILENAME_EXTENSIONS, '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_session('header', WARNING_NO_FILE_UPLOADED,
'warning');
} else {
$messageStack->add_session('upload', 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)) {
$width = 100;
$height = 100;
list($width_orig, $height_orig) = getimagesize($this->destination .
$this->filename);

if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($this->destination . $this->filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
imagejpeg($image_p, $this->destination . '/th/'. $this->filename,
100);
chmod($this->destination . '/th/'. $this->filename,
$this->permissions);
if ($this->message_location == 'direct') {
$messageStack->add_session('header',
SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
} else {
$messageStack->add_session('upload',
SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
}

return true;
} else {
if ($this->message_location == 'direct') {
$messageStack->add_session('header', ERROR_FILE_NOT_SAVED, 'error');
} else {
$messageStack->add_session('upload', 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 (zen_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_session('header',
sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error');
} else {
$messageStack->add_session('upload',
sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error');
}
} else {
if ($this->message_location == 'direct') {
$messageStack->add_session('header',
sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error');
} else {
$messageStack->add_session('upload',
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;
}
}
}


Jun 23 '07 #1
0 1654

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Spud | last post by:
<?php // pullpage function by Nick bouton http://www.nickbouton.com/. $CustomerID = "IDHERE"; $method = "POST"; $host = "xml.mydata.com"; $usepath = "/xml.asp"; //print all vars in an...
3
by: Robert | last post by:
Hello, Can anyone help with this? On my online order form, I need to send a few variables to my credit-card processor. These variables are for non-secure customer comments, and will be sent...
8
by: bmgx | last post by:
I would like to use an already existing online service (currency converter) basically consisting of a html form with a few options that is submitted and returns the results. I really don't know...
5
by: Nelson Minar | last post by:
I'm writing some code to upload photos to Flickr. The Photo Upload API requires documents be POSTed via a multipart/form-data request. I was surprised to learn that Python 2.3's HTTP clients don't...
2
by: vm | last post by:
Hi, for some reason my POST is not working properly. I am basically just trying to get a simple stock quote from yahoo by posting the ticker symbol (GE as an example) into finance.yahoo.com. ...
3
by: Tim Wade | last post by:
Does anyone have any ideas on how to do an automatic html form post using hidden fields without introducing client-side script nor using a server-side WebRequest by passing the information back up...
2
by: Mike | last post by:
I need to POST some hidden fields to a page, which i need to load in the browser window.. i've tryed writting out the hidden fields and doing a response.redirect/response.transfer but these don't...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
24
by: moriman | last post by:
Hi, The script below *used* to work. I have only just set up a server, PHP etc again on my Win98 system and now it doesn't? On first loading this page, you would have $p = and the button...
1
by: ERobishaw | last post by:
Using Winform app writing a HTTP Post using the following... on the server side, I get no form fields. Request.Form.AllKeys.Length = 0. If I put the field/value paris in the URL I can use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.