PDA

View Full Version : Increment file name problem


phil.evans372967
04-28-2009, 09:09 AM
Hi all

I'm trying to upload multiple images data and images to a table prop_images which relate to one record in another table prop_details by redirecting back to the images input form after each sumbit.

The upload and insert record works each time, however the file name only increments once (adds _1.jpg) and then keeps adding _1.jpg so files images are being overwritten. I'm using a variable as the main part of the file name and concaternating with [Increment].jpg for the rename new file action if file exists.

Can anyone help? - Code is below.

Thanks

Phil

<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(isset($_POST["Insert_x"])){
WA_DFP_UploadFile("WA_UploadResult1", "img_thumb", "../images/tns/tn_default.jpg", "../images/tns/", "".$row_propid_for_ims['prop_id'] .".jpg", "2", "".$row_propid_for_ims['prop_id'] ."_[Increment].jpg", "0", "false", "0", "0");
}
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult2");
if(isset($_POST["Insert_x"])){
WA_DFP_UploadFile("WA_UploadResult2", "img_main", "../images/main/default_main.jpg", "../images/main/", "".$row_propid_for_ims['prop_id'] ."", "2", "".$row_propid_for_ims['prop_id'] ."_[Increment].jpg", "0", "false", "0", "0");
}
?>

Danilo Celic
04-28-2009, 10:19 AM
Try removing the .jpg from the rename token. So for your first upload you'd have:
"".$row_propid_for_ims['prop_id'] .""

and for your second one, you'd have:
"".$row_propid_for_ims['prop_id'] ."_[Increment]"


The renaming code that find a unique name builds a file name from this value plus the file extension of the uploaded file, and with the file extension in that value it was incorrectly determining the new file name.

phil.evans372967
04-30-2009, 06:40 AM
Hi Dan,

Thanks for your help.

That worked perfectly

Regards

Phil