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

Delete specific Image File when uploading new images.

Thread began 6/24/2010 10:25 am by Digibug | Last modified 6/28/2010 10:31 am by Jason Byrnes | 3550 views | 5 replies |

Digibug

Delete specific Image File when uploading new images.

This is hard to explain so please hang in there!!

Ok I have a form that is allowing users to upload a total of 12 images, the images upload to a specified folder and data is inserted into the database. Users can re-upload any of the 12 images they want so for example they can choose to replace image 3, 5 & 7 buy clicking the upload file and then clicking the upload button, the files are then replaced on the server and the name is exactly the same, this works like a charm.

What I have also done is created an image cropping section where users can click any of the 12 images they've uploaded and this will then alow them to crop a section of the image and this then saves a new photo to the server called img1-cropped.jpg

Still with me!!

What I really need to do is get the update page to delete any of these cropped images from the server when a new photo is uploaded, so for example, if i upload a new photo to replace image1.jpg I need the form to remove img1-cropped.jpg during the same process. This so when the user view the crop image page they don't see the wrong (old) image anymore.

I though i cracked it by including:

$WA_DeleteFileResult2 = WA_FileAssist_DeleteFile("../../assets/uploads/events/images/", "".$row_DLA_Event['ID'] ."img12-cropped.jpg");

Within the WA_DFP_SetupUploadStatusStruct command, it works BUT it removes every cropped image even if i only upload one new photo, here is the small code block i used.




<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult2");
if(isset($_POST["submit_x"])){
WA_DFP_UploadFiles("WA_UploadResult2", "new_img1", "0", "", "JPG:70", $WA_UploadResult2_Params);
$WA_DeleteFileResult2 = WA_FileAssist_DeleteFile("../../assets/uploads/events/images/", "".$row_DLA_Event['ID'] ."img1-cropped.jpg");
}
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult3");
if(isset($_POST["submit_x"])){
WA_DFP_UploadFiles("WA_UploadResult3", "new_img2", "0", "", "JPG:70", $WA_UploadResult3_Params);
$WA_DeleteFileResult2 = WA_FileAssist_DeleteFile("../../assets/uploads/events/images/", "".$row_DLA_Event['ID'] ."img2-cropped.jpg");
}?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult4");
if(isset($_POST["submit_x"])){
WA_DFP_UploadFiles("WA_UploadResult4", "new_img3", "0", "", "JPG:70", $WA_UploadResult4_Params);
$WA_DeleteFileResult2 = WA_FileAssist_DeleteFile("../../assets/uploads/events/images/", "".$row_DLA_Event['ID'] ."img3-cropped.jpg");
}?>


Do you know how I can achieve this, delete a specific file from the server that matches the relevent image uploaded.

Really hope this makes sense, i've posted quite a few times with different problems throughout the forum without much resolve so am hoping to crack this one.

Thanks
Lee

Sign in to reply to this post

Jason ByrnesWebAssist

the new cropped image is being created with the same name as the old one right?

If so, set the If File Exists option to overwrite.

If this is not the case, compress the php file to a zip archive and attach that to your post so I can get a better sense of the code in context.

Sign in to reply to this post

Digibug

Hi Jason,

The cropped images does replace the old one but it's not really the cropping section i'm having a problem with.

I've attached a zip file that includes the cropping process & the image update page.

The process is currently like this:
&#8226; User uploads up to 12 images - the system resizes and saves two files
&#8226; User is then going to be taken to a page that displays all uploaded images
&#8226; User is then able to crop any image of the uploaded images and a new additional file is saved called cropped.
&#8226; The page that displays the images is then refreshed to show the new cropped image
&#8226; The user can then click the next image and crop, page refreshes and repeat until cropping is complete.

The problem i have is when the user replaces any of the original images they've uploaded, the page that shows the cropped images will not change because the cropped image is still on the server even though the new uploaded images have successfully overwritten and replaced the 2 resized pictures.

What I need to do is delete the cropped picture when a new image is uploaded, so:

Upload new image 3 and system overwrites the 2 resized and deletes cropped image 3
Upload new image 4 and system overwrites the 2 resized and deletes cropped image 4
Upload new image 6 and system overwrites the 2 resized and deletes cropped image 6

Etc...

I've got it to delete cropped images but it's deleting all of them rather than the ones that relate to the new images being uploaded.

Hope this makes sense, i've zipped up the code of the pages in question so you can see.

Thanks so much for taking a look for me, really hope you can help.

Lee

P.S. This cropping setup is really good, you guys should consider including a feature like this on Powerstore or your CMS setup.

Attached Files
php files.zip
Sign in to reply to this post

Jason ByrnesWebAssist

your file names are using a variable from a recordset:
$row_DLA_Event['ID'] ."img1"

The DLA_Event recordset is set to filter on a querystring variable that is not passed when the form submits:

<form action="" method="post" enctype="multipart/form-data" class="middle-forms" id="add_media">

I think the main cause of the issue is that the images are not being properly to begin with.


change the forms action to:

php:
 action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""?>"




this will make sure any querystring variables that are passed in get passed along with the form submission.

Sign in to reply to this post

Digibug

Hi Jason,

Thanks for the form action, i've put it in place and then tried to upload replacement images but it still deletes all the cropped photos rather then the one that is relevant to the new uploading file field that is being submitted.

I've been racking my brain all morning and have finally found a solution that works.
This looks at the submitted form, checks the file filed to see if it's empty, if it is nothing happens, if it isn't it deletes a specific file from the server.

Here is the code I used just in case anyone else needs a solution.


<?php
$WA_DeleteFileResult1 = false;
if(isset($_POST["submit_x"])){
if (!empty($_FILES['new_img1']['name'])) {
//Delete Cropped Image
$WA_DeleteFileResult1 = WA_FileAssist_DeleteFile("../../assets/uploads/events/images/", "".$row_DLA_Event['ID'] ."img1-cropped.jpg");
}}
?>

Now all of the 12 file upload boxes will upload new images and delete a specific file from the server per filed (12 uploads, 12 files deleted) all on the fly.

Thanks for your help.
Lee

Sign in to reply to this post

Jason ByrnesWebAssist

excellent, glad to hear you have it working.

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