Guest Posted January 13, 2005 Posted January 13, 2005 The code I'm using seems to work like a charm on my other site, but I didn't develop the code so I'm unsure if there is something amiss. Here goes. My store needs a function that will allow a customer to upload a file after placing an order. This file needs to be prepended with the order number and uploaded to a designate folder. The problem: I can't seem to a) get the order number to come fromt he database, even when using the HTPP_GET_VARS command and calling for 'orders_id' and B) get the file to upload at all. The old script had a "destination" denoted, but the script I have, that actually WORKS, doesn't have a destination. First things first, I need to at LEAST get the order number to pop up. Here is the code above the "head" tag: $error = false; if ( ($HTTP_GET_VARS['orders_id'] == "") && (!isset($HTTP_POST_VARS['orders_id'])) ) { $error = true; $messageStack->add('upload', "You must specify an Order ID for uploading"); } else { $error = false ; if (isset($HTTP_POST_VARS['orders_id']) && isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'upload')) { // perform upload $orders_id = tep_db_prepare_input($HTTP_POST_VARS['orders_id']); $reupload = tep_db_prepare_input($HTTP_POST_VARS['reupload']); $noinput = true; for($i=1; $noinput && ($i<=UPLOAD_NO); $i++) { //echo "<HR>infile$i=${"infile".$i}<HR>" ; if(${"infile".$i}!="") $noinput=false; } if ( $noinput ) { $error = true ; $messageStack->add('upload', "You did not specify any files to upload. Try again!") ; } else { $slash = ( strstr( PHP_OS, "WIN") ? "\\" : "/" ) ; // make order subdirectory // COMMENTED OUT SUBDIR PER BCS !!! 2004-12-01 // if ( ! is_dir(DESTINATION . $slash . $orders_id)) { // if ( ! (mkdir(DESTINATION . $slash . $orders_id)) ) { // $error = true ; // $messageStack->add('upload', "We had trouble storing your files. Please contact the webmaster!") ; // } // } for($i=1; $i<=UPLOAD_NO; $i++) { $just=filesize(${"infile".$i}); $fp_size = $just; // // WAS: got rid of orders_id subfolder... // copy ( ${"infile" . $i}, DESTINATION . $slash . $orders_id . $slash . $orders_id . "_" . ${"infile" . $i . "_name"} ) // if ( ( ${"infile".$i} != "" ) && copy ( ${"infile" . $i}, DESTINATION . $slash . $orders_id . "_" . ${"infile" . $i . "_name"} ) && unlink ( ${"infile" . $i} ) ) { $messageStack->add('upload', "Processed file " . $i . " - " . ${"infile" . $i . "_name"} . " - " . $fp_size . " bytes") ; } else { // only raise error if ${"infile".$i} really has a value but could not be processed if ( ${"infile".$i} != "" ) { $error = true ; $messageStack->add('upload', "Could not upload file " . $i . " - " . ${"infile" . $i . "_name"}) ; } } } } if (!$error) { // success message // !!! BCS 2004-12-01 if success AND was a RE-UPLOAD (reupload<>0) then change status of order in database if ( $reupload == "1" ) { tep_db_query("update orders set orders_status = 1 where orders_id = " . $orders_id); } tep_redirect(tep_href_link(FILENAME_UPLOAD_SUCCESS, 'orders_id=' . ORDERS_ID . '&action=success')); } } } if ($messageStack->size('upload') > 0) { echo $messageStack->output('upload'); } $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_UPLOAD)); ?> and the really simple stuff from after the header: <table border="0" width="100%" cellspacing="3" cellpadding="3"> <tr> <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2"> <!-- left_navigation //--> <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?> <!-- left_navigation_eof //--> </table></td> <!-- body_text //--> <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="pageHeading"><?php echo HEADING_TITLE; ?></td> </tr> </table></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> <tr> <td class="main"><?php echo TEXT_MAIN;?></td> </tr> <td><br> <div align="center" class="pageHeading"><font size="4">Order #<?php echo ORDERS_ID ?> - Files to Upload</font></div> <br> <form enctype='multipart/form-data' action="uploadfiles.php" method='post'> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="50000000"> <INPUT TYPE="hidden" name="action" value="upload"> <INPUT TYPE="hidden" name="orders_id" value="<?php echo ORDERS_ID ?>"> <INPUT TYPE="hidden" name="reupload" value="<?php echo $HTTP_GET_VARS['reupload'] ?>"> <table border="0" width="90%" align="center" cellspacing="0" cellpadding="0"> <tr> <td><input type="file" name="infile1" size="25"></td> <td> </td> <td> </td> <td> </td> <td><input type="file" name="infile4" size="25"></td> </tr> <tr> <td><input type="file" name="infile2" size="25"></td> <td> </td> <td> </td> <td> </td> <td><input type="file" name="infile5" size="25"></td> </tr> <tr> <td><input type="file" name="infile3" size="25"></td> <td> </td> <td> </td> <td> </td> <td><input type="file" name="infile6" size="25"></td> </tr> </table> <br> <br> <div align="center"> <input type="Submit" value=" Upload NOW "> </div> </form></td> </tr> <tr> <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td> </tr> </table></td> </tr> </table> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> Please advise if you can. Thanks.
Guest Posted January 13, 2005 Posted January 13, 2005 Hi, I can't help with the code but you might try looking at the contribution: http://www.oscommerce.com/community/contri...rch,file+upload which I have installed on my site and works a treat for uploading files. It enables you to upload files at the product selection stage, but you may be able to get some ideas for your situation by looking at the code. Hope this is of some help.
Guest Posted January 13, 2005 Posted January 13, 2005 That's not exactly what I'm looking for. Ironically enought though, I looked at that before I posted this. We are thinking along the same lines then huh?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.