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

Adding a photo - if one already exits in another record

Thread began 12/04/2012 8:05 am by thehalpeen319342 | Last modified 12/04/2012 12:59 pm by thehalpeen319342 | 1577 views | 2 replies |

thehalpeen319342

Adding a photo - if one already exits in another record

Dear Jason,
Question 1
A while back you advise me to select 'rename new file' in the action file, if I wish to populate a database with a filename that another user had used - say myphoto.jpg. When I upload the photo, the database field called 'photo' is populated with the name of the jpeg 'myphoto.jpg', but now I have two records with the same name for their photos.


The photos are being renamed correctly in the images folder, but as I said above, the new names - with the increment are not shown in the database.
See code below:

Question 2
I've also created a jpg called 'noimage.jpg' and this is the default image, that will be used if a user does not submit an image. The problem is that when a record is inserted (with no image), the default value that I setup in the database ('noimage.jpg') is not inserted - is this because I'm inserting a record called blank. How do I get it to default to ''noimage.jpg' if the user inserts nothing?


<?php require_once('Connections/CommSimpleRegister.php'); ?>
<?php require_once("webassist/database_management/wa_appbuilder_php.php"); ?>
<?php require_once("webassist/file_manipulation/helperphp.php"); ?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "member_photos/",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "4",
'ResizeWidth' => "150",
'ResizeHeight' => "100",
'ResizeFillColor' => "#FFFFFF" );
// WA_UploadResult1_1 End
// WA_UploadResult1_2 Start
$WA_UploadResult1_Params["WA_UploadResult1_2"] = array(
'UploadFolder' => "member_photos/thumbs/",
'FileName' => "[FileName]_thumb",
'DefaultFileName' => "",
'ResizeType' => "4",
'ResizeWidth' => "40",
'ResizeHeight' => "60",
'ResizeFillColor' => "#FFFFFF" );
// WA_UploadResult1_2 End
// WA_UploadResult1 Params End
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)){
WA_DFP_UploadFiles("WA_UploadResult1", "photo", "2", "[ExistingFileName]_[Increment]", "JPG:80", $WA_UploadResult1_Params);
}
?>
<?php

// WA DataAssist Insert
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) // Trigger
{
$WA_connection = $CommSimpleRegister;
$WA_table = "test_table";
$WA_sessionName = "testSession_ID";
$WA_redirectURL = "";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_fieldNamesStr = "f_name|l_name|email|phone|password|photo";
$WA_fieldValuesStr = "".((isset($_POST["f_name"]))?$_POST["f_name"]:"") ."" . $WA_AB_Split . "".((isset($_POST["l_name"]))?$_POST["l_name"]:"") ."" . $WA_AB_Split . "".((isset($_POST["email"]))?$_POST["email"]:"") ."" . $WA_AB_Split . "".((isset($_POST["phone"]))?$_POST["phone"]:"") ."" . $WA_AB_Split . "".((isset($_POST["password"]))?$_POST["password"]:"") ."" . $WA_AB_Split . "".((isset($_FILES["photo"]))?$_FILES["photo"]["name"]:"") ."";
$WA_columnTypesStr = "',none,''|',none,''|',none,''|none,none,NULL|',none,''|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode($WA_AB_Split, $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_CommSimpleRegister;
mysql_select_db($WA_connectionDB, $WA_connection);
@session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id($WA_connection);
if ($WA_redirectURL != "") {
$WA_redirectURL = str_replace("[Insert_ID]",$_SESSION[$WA_sessionName],$WA_redirectURL);
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<!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>Test Upload</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<form id="reg_Form" name="reg_Form" method="post" action="">
<p>
<label for="f_name">First Name</label>
<input type="text" name="f_name" id="f_name" />
enter a first name</p>
<p>
<label for="l_name">Last Name</label>
<input type="text" name="l_name" id="l_name" />
</p>
<p>
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</p>
<p>
<label for="phone">Phone</label>
<input type="text" name="phone" id="phone" />
</p>
<p>
<label for="password">Password</label>
<input type="password" name="password" id="password" />
</p>
<p>
<label for="photo">photo</label>
<label for="photo2"></label>
<input type="file" name="photo" id="photo2" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>



</form>
</body>
</html>

Sign in to reply to this post

Jason ByrnesWebAssist

1) when using File Upload, a new binding group is created on the binding panel, "WA Uploaded File (<File field name>)", where <File field name> is the name of your file field. This binding group contains a Server File Name binding that contains the name of the file that is created in the server

in the insert record and update record behaviors, bind the image column to the Server File name binding

1) In the file upload behavior, set the Default File setting to noimage.jpg

Sign in to reply to this post

thehalpeen319342

Jason, that's fantastic. I've got a pretty interesting membership database almost developed, with, would you believe, pictures of the members now possible. This project took on a few extra legs, but I'm beginning to see light at the end of the tunnel. There's a little bit to go yet, but you've been a great help along the journey.

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...