close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

On file upload, if file exists and no new file is selected for upload, leave existing

Thread began 5/22/2019 11:27 am by lr_leal239405 | Last modified 12/08/2020 10:03 am by Ray Borduin | 1348 views | 10 replies |

lr_leal239405

On file upload, if file exists and no new file is selected for upload, leave existing

Another thing I'm trying to achieve is - I have the File Upload function working, but I don't want it to erase what's already there on the UPDATE page when there's no file selected. (I have 3 actually). I have tried the codes's below, but it always gets erased:

<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if($_FILES["Image"]["name"] == "") {
if(isset($_POST["Update"]) || isset($_POST["Update_x"])){
WA_DFP_UploadFiles("WA_UploadResult1", "Image", "0", "", "true", $WA_UploadResult1_Params);
}
}
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult2");
if(!empty($_FILES)) {
if(isset($_POST["Update"]) || isset($_POST["Update_x"])){
WA_DFP_UploadFiles("WA_UploadResult2", "Image2", "0", "", "true", $WA_UploadResult2_Params);
}
}
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult3");
if(!empty($_FILES['Image3'])) {
if(isset($_POST["Update"]) || isset($_POST["Update_x"])){
WA_DFP_UploadFiles("WA_UploadResult3", "Image3", "0", "", "true", $WA_UploadResult3_Params);
}
}
?>

Sign in to reply to this post

Ray BorduinWebAssist

You have your bindings set to update from the form. You should use the "Server File Name" binding from the file upload server behavior bindings.

instead of:

php:
$UpdateQuery->bindColumn("Image", "s", "".((isset($_FILES["Image"]))?($_FILES["Image"]["name"]):"")  ."", "WA_BLANK");


it will be something like:

php:
$UpdateQuery->bindColumn("Image", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["serverFileName"])  ."", "WA_BLANK");
Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

Yeah, that works now. Not sure what WA_DFP_UploadStatus does or what ["serverFileName"] vs. ["name"] is exactly, but it works ! Thank you.

Sign in to reply to this post

lr_leal239405

We realized we can't delete on Update once there's a file there because it's updating from Server. Works great, but now......I would like to add an option to delete. Do I have to add a checkbox and write a function? I'm looking for simple approach.

I have this now

$UpdateQuery->bindColumn("prod_img", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["serverFileName"]) ."", "WA_BLANK");

Sign in to reply to this post

Ray BorduinWebAssist

I would probably add a separate form with a hidden form element containing the file path and a hidden form element with the database record ID. Thenn use the Delete File Server Behavior and Update Record to clear out the old value based on the form button and hidden form element value.

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

Just to update this, a while back, what I did was added a checkbox that deletes the field data when selected.

I simply changed this on the Update function:

if (isset($_POST['delImg'])) {
$UpdateQuery->bindColumn("prod_img", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["Name"]) ."", "WA_BLANK");
} else {
$UpdateQuery->bindColumn("prod_img", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["serverFileName"]) ."", "WA_BLANK");
}

Not sure if it's good practice but it works fine for this purpose.

Sign in to reply to this post

lr_leal239405

Hi. A while back I asked this question and it seemed to resolve. However it won't work on this new page:

On Update, code below still erases the photo that is already there. Is the code above correct? should it leave the picture if already existing one? Thanks for your help.

<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../../tips/images/",
'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["Update"]) || isset($_POST["Update_x"])){
WA_DFP_UploadFiles("WA_UploadResult1", "tip_photo", "0", "", "false", $WA_UploadResult1_Params);
}
?>

$UpdateQuery->bindColumn("tip_photo", "s", "".($WA_DFP_UploadStatus["WA_UploadResult1"]["WA_UploadResult1_1"]["serverFileName"]) ."", "WA_BLANK");

Sign in to reply to this post

Ray BorduinWebAssist

Yes... on this line:

WA_DFP_UploadFiles("WA_UploadResult1", "tip_photo", "0", "", "false", $WA_UploadResult1_Params);

the "0" means overwrite. To rename the new file with a number use:

WA_DFP_UploadFiles("WA_UploadResult1", "tip_photo", "2", "", "false", $WA_UploadResult1_Params);

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

It keeps deleting the existing file name form table column any time I press the "Update' button. I tried after changing to 2 per your instructions (also tried 1 and 3 btw). No matter what, it removes the file name from the table column.

Attached is the entire file. Thank you.

Sign in to reply to this post

lr_leal239405

Ok, I found a workaround. Never mind for now. Thanks.

Sign in to reply to this post
loading

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