close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Getting File Upload to work

Thread began 1/13/2010 1:25 pm by jay.malik396220 | Last modified 1/13/2010 7:46 pm by Jason Byrnes | 4031 views | 7 replies |

jay.malik396220

Getting File Upload to work

My action code is in a separate file, and I've tried to move code as best as I can guess.

The file upload is not working as a consequence. I will also have an issue adding the attachment to email as a second item.

Here's the form code:

<?php
if (!isset($_SESSION)) {
session_start();
}
?>
<?php require_once( "../../WA_SecurityAssist/Helper_PHP.php" ); ?>
<?php
if (!WA_Auth_RulePasses("Customer Access")){
WA_Auth_RestrictAccess("accessdenied.php");
}
require_once("../../WA_DigitalFilePro/HelperPHP.php");
//WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
//WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../uploads",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmln
.
.
.
<form enctype="multipart/form-data" action="processsupportrequest.php" method="post" name="form1" class="FormContent" id="form1">
.
.
<tr>
<td>Attachments:</td>
<td><span id="sprytextfield6">
<input name="upload" id="upload" type="file"/>
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>

Here's the processing code:
<?php
if (!isset($_SESSION)) {
session_start();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
require_once('../../Connections/Centerline.php'); ?>
<?php require_once("../../WA_DigitalFilePro/HelperPHP.php"); ?>
<?php require_once("../../WA_Universal_Email/mail_PHP.php"); ?>
<?php require_once("../../WA_Universal_Email/MailFormatting_PHP.php"); ?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();

if ($securimage->check($_POST['captcha_code']) == true) {
// capthca entered correctly

WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
WA_DFP_UploadFiles("WA_UploadResult1", $_FILES["upload"], "3", "[ExistingFileName]_[Increment]", "false", $WA_UploadResult1_Params);

//WA Universal Email object="mail"
//Send Loop Once Per Entry
$RecipientEmail = "support@centerlinesft.com";include("../../WA_Universal_Email/WAUE_processsupportrequest_1.php");

//Send Mail All Entries
header("Location: ");

$insertGoTo = "thankyouemail.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
else {
print '<p align="center" style="color: #DD0000; font-weight: bold;">Incorrect verification code</p>';
print '<p align="center"><a href="javascript:history.go(-1);">Go back and try again</a></p>';
}
?>
</body>
</html>

And the email template:
<?php
$MailAttachments = "";
$MailBCC = "";
$MailCC = "";
$MailTo = "";
$MailBodyFormat = "";
$MailBody = "";
$MailImportance = "";
$MailFrom = "Centerline Support Page|WA|support@centerlinesft.com";
$MailSubject = "Support Request - " . $_POST["Name"];
$_SERVER["QUERY_STRING"] = "";

//Global Variables

$WA_MailObject = WAUE_Definition("mail.allabuzz-ci.com","25","support@centerlinesft.com","","","");

if ($RecipientEmail) {
$WA_MailObject = WAUE_AddRecipient($WA_MailObject,$RecipientEmail);
}
else {
//To Entries
}

//Attachment Entries

//BCC Entries

//CC Entries

//Body Format
$WA_MailObject = WAUE_BodyFormat($WA_MailObject,0);

//Set Importance
$WA_MailObject = WAUE_SetImportance($WA_MailObject,"3");

//Start Mail Body
$MailBody = $MailBody . "<html><head></head><body>\r\n";
$MailBody = $MailBody . "\r\n";
$MailBody = $MailBody . "<p>Name: ";
$MailBody = $MailBody . ((isset($_POST["Name"]))?$_POST["Name"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "<p>Email: ";
$MailBody = $MailBody . ((isset($_POST["Email"]))?$_POST["Email"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "<p>Comments: ";
$MailBody = $MailBody . ((isset($_POST["Comments"]))?$_POST["Comments"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "<p>Attachment: ";
$MailBody = $MailBody . ((isset($_FILES["upload"]))?$_FILES["upload"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "</body></body></html>";
//End Mail Body

$WA_MailObject = WAUE_SendMail($WA_MailObject,$MailAttachments,$MailBCC,$MailCC,$MailTo,$MailImportance,$MailFrom,$MailSubject,$MailBody);

$WA_MailObject = null;
?>

Sign in to reply to this post

Jason ByrnesWebAssist

1) Some of the Digital file Pro code was not copied from the from page to the processing page:

php:
//WA_UploadResult1 Params Start

$WA_UploadResult1_Params = array();
//WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../uploads",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End




2) in the DFP Server behavior, you do not need to click the lightning bolt next to the File Filed, instead, you should select the name of the file field from the drop down list.

3) In the email, you should not refer to the file from the file collection, instead, expand the WA Digital File pro Uploaded Files group and select the Server File name.

instead of having the form post to another page, it is much simpler to have the form post to itself, and add the upload and email server behaviors to the same page, you dont have top copy from one page to another that way.

Sign in to reply to this post

jay.malik396220

Post action

Thanks Jason,

The main reason I use a different page is because I have not figured out how to test the captcha code and show an error on the same page (pretty much the same as your contact form for WebAssist).

Form code for captcha code is:

<tr valign="baseline">
<td align="right" nowrap="nowrap" class="InputTables"><p><img src="/securimage/securimage_show.php?sid=<?php echo md5(time()) ?>" alt="captcha" align="left" id="siimage" style="padding-right: 5px; border: 0" /><br />
<!-- pass a session id to the query string of the script to prevent ie caching -->
</p>
<p><a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = '/securimage/securimage_show.php?sid=' + Math.random(); return false"></a></p></td>
<td> <input type="text" name="captcha_code" size="10" maxlength="6" /></td>
</tr>

Error check code is:
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();

if ($securimage->check($_POST['captcha_code']) == true) {
// capthca entered correctly

WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");

.
.
.

else {
print '<p align="center" style="color: #DD0000; font-weight: bold;">Incorrect verification code</p>';
print '<p align="center"><a href="javascript:history.go(-1);">Go back and try again</a></p>';
}
?>

Sign in to reply to this post

Jason ByrnesWebAssist

I see no reason why this code cannot be on the same page as the form.

Sign in to reply to this post

jay.malik396220

Simple Example

I created a new and simple form with all behaviors in the same page. No upload, and no attachment to the email (no errors raised either).

Form Code:
<?php require_once("../../WA_DigitalFilePro/HelperPHP.php"); ?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../uploads",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(isset($_POST["send"])){
WA_DFP_UploadFiles("WA_UploadResult1", "upload", "0", "", "false", $WA_UploadResult1_Params);
}
?>
<?php require_once("../../WA_Universal_Email/mail_PHP.php"); ?>
<?php require_once("../../WA_Universal_Email/MailFormatting_PHP.php"); ?>
<?php
if ((isset($_POST["send"]))) {
//WA Universal Email object="mail"
//Send Loop Once Per Entry
$RecipientEmail = "jay@pivotier.com";include("../../WA_Universal_Email/WAUE_upload_1.php");

//Send Mail All Entries
header("Location: ");

$insertGoTo = "thankyouemail.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="../../Templates/Centerline_Pages.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../Assets/CSS/centerline_09.css" rel="stylesheet" type="text/css" />
<!--
-->
<!--[if lte IE 6]>
<style type="text/css" media="all">
@import url("../../CSSMenuWriter/cssmw/menu_ie.css");
</style><![endif]-->
<script type="text/javascript" src="../../CSSMenuWriter/cssmw0/menu.js"></script>
<style type="text/css" media="all">
<!--
@import url("../../CSSMenuWriter/cssmw0/menu.css");
-->
</style>
<!--[if lte IE 6]>
<style type="text/css" media="all">
@import url("../../CSSMenuWriter/cssmw0/menu_ie.css");
</style><![endif]-->
<!--[if lte IE 6]>
<style type="text/css" media="all">
@import url("../../CSSMenuWriter/cssmw1/menu_ie.css");
</style><![endif]-->

<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>


<!-- InstanceBeginEditable name="doctitle" -->
<title>SSRS Reporting for Dynamics NAV</title>
<!-- InstanceEndEditable -->


<meta name="Keywords" content="Microsoft Dynamics NAV,SSRS,Reporting Services,Pivotier,Flowfields,Report Definition Language,RDL,SQL Server" />
</head>

<body>
<div id="content">
<div id="Header">
<div id="leftcolumnbubble"></div>
<div id="rightcolumnbubble"></div>
<div id="gutterbubble"></div>
<div id="headerbubble"></div>
<div id="logo">
<div id="cline"><img src="../Assets/Elements/CEN_Weblogo.png" alt="logo" width="274" height="64" hspace="10" vspace="5" border="0" usemap="#GoHome" onload="MM_preloadImages('Assets/Elements/CEN_Webbox_TopLeft_03.png','Assets/Elements/images/currency.png','Assets/Elements/images/jumpers.png','Assets/Elements/images/Modernize.png','Assets/Elements/images/SSRS.png','Assets/Elements/images/visualize.png')" />
<map name="GoHome" id="GoHome">
<area shape="rect" coords="5,5,270,59" href="Centerline_Home.php" alt="Go to home page" />
</map>
</div>
<div id="title"><br />
<p><!-- InstanceBeginEditable name="Page_Menu_Text" -->Page_Menu_Text<!-- InstanceEndEditable --></p>
<div id="TitleBubble"></div>
</div>
</div>
<div id="navigation">
<p><?php require_once("../../CSSMenuWriter/cssmw0/menu.php"); ?></p>
</div>
</div>
<div id="pagecontent">
<div class="leftcolumn"><b class="rtop"><b class="r1"></b> <b class="r2"></b> <b class="r3"></b> <b class="r4"></b></b>
<div id="leftcolumncontent"><!-- InstanceBeginEditable name="Left_Column" -->Left_Column<!-- InstanceEndEditable --></div>
<b class="rbottom"><b class="r4"></b> <b class="r3"></b> <b class="r2"></b> <b class="r1"></b></b>
</div>
<div class="rightcolumn"><b class="rtop"><b class="r1"></b> <b class="r2"></b> <b class="r3"></b> <b class="r4"></b></b>
<div id="rightcolumncontent"><!-- InstanceBeginEditable name="Right_Column" -->
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>&nbsp;</p>
<p>
<label>Name
<input type="text" name="name" id="name" />
</label>
</p>
<p>
<label>Email
<input type="text" name="email" id="email" />
</label>
</p>
<p>
<label>Select a File
<input type="file" name="upload" id="upload" />
</label>
</p>
<p>
<label>
<input type="submit" name="send" id="send" value="Send" />
</label>
</p>
</form>
<!-- InstanceEndEditable --></div>
<b class="rbottom"><b class="r4"></b> <b class="r3"></b> <b class="r2"></b> <b class="r1"></b></b>
</div>
</div>
<div id="footer">
<a href="contactus.php">Contact</a> | <a href="terms.php">Terms of Use</a> | <a href="privacy.php">Privacy</a> | <a href="Login.php">Login</a> | <a href="logout.php">Logout</a> | <a href="Centerline_Home.php">Home</a><br />
<br />
Copyright &copy; 2009-2010 Centerline Software, Inc. </div>
</div>
</body>
<!-- InstanceEnd --></html>

Email code:
<?php
$MailAttachments = "";
$MailBCC = "";
$MailCC = "";
$MailTo = "";
$MailBodyFormat = "";
$MailBody = "";
$MailImportance = "";
$MailFrom = "".$_SESSION['FirstName'] ."|WA|".$_SESSION['Email'] ."";
$MailSubject = "Support Email";
$_SERVER["QUERY_STRING"] = "";

//Global Variables

$WA_MailObject = WAUE_Definition("mail.allabuzz-ci.com","25","","","","");

if ($RecipientEmail) {
$WA_MailObject = WAUE_AddRecipient($WA_MailObject,$RecipientEmail);
}
else {
//To Entries
}

//Attachment Entries
//$WA_MailObject = WAUE_AddAttachment($WA_MailObject,"".((isset($_COOKIE[""]))?$_COOKIE[""]:"") ."");
$WA_MailObject = WAUE_AddAttachment($WA_MailObject,"".(realpath("../".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"])) ." ");


//BCC Entries

//CC Entries

//Body Format
$WA_MailObject = WAUE_BodyFormat($WA_MailObject,0);

//Set Importance
$WA_MailObject = WAUE_SetImportance($WA_MailObject,"3");

//Start Mail Body
$MailBody = $MailBody . "<html><head></head><body>\r\n";
$MailBody = $MailBody . "\r\n";
$MailBody = $MailBody . "<p>Name: ";
$MailBody = $MailBody . ((isset($_POST["name"]))?$_POST["name"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "<p>Email: ";
$MailBody = $MailBody . ((isset($_POST["email"]))?$_POST["email"]:"");
$MailBody = $MailBody . "</p>\r\n";
$MailBody = $MailBody . "</body></body></html>";
//End Mail Body

$WA_MailObject = WAUE_SendMail($WA_MailObject,$MailAttachments,$MailBCC,$MailCC,$MailTo,$MailImportance,$MailFrom,$MailSubject,$MailBody);

$WA_MailObject = null;
?>

Sign in to reply to this post

Jason ByrnesWebAssist

to trouble shoot, add the following at line 1:

php:
<?php

error_reporting
(E_ALL);
ini_set('display_errors','on');
?>




Then open the Bindings panel, expand the WA Uploaded Files Global Status and add the debug info binding to the page.


Post back the debug info after trying to upload a file.

Sign in to reply to this post

jay.malik396220

Post Back?

Sorry to be dense, but how do I post back the debug info.

I have inserted Debug Info on the form.

Right now when submitted it finishes and then presents a page refresh error . Going back does not show the debug info.

Sign in to reply to this post

Jason ByrnesWebAssist

What I meant was to copy the debug info from your page into your response.


if you are getting an error, you will need to provide the full error text for me to have an idea of the cause. If you could also include a zip file with the php page, that would help tracking down the error as well.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...