spdwrench Posted October 3, 2007 Share Posted October 3, 2007 I need to swap two files for example /photos/jim1.jpg and /photos/jim3.jpg if I need jim3 to become jim1 and jim1 to become jim3 do I need to first save one of them as a new file or is there some kind of swap command that will just swap the two? anyway help is appreciated I am currently working on it to rename jim1 to swap and rename jim3 to jim1 and then swap to jim3 is there an easier way? Paul Quote Link to comment https://forums.phpfreaks.com/topic/71685-solved-need-to-swap-two-files-they-are-photos-being-swapped-is-there-a-command/ Share on other sites More sharing options...
shocker-z Posted October 3, 2007 Share Posted October 3, 2007 yes because of your file system not allowing duplicate names (standard law of things) you would have to do somthing like Copy jim1 jim3tmp copy jim3 jim1 copy jim3tmp jim3 I spose you could hold the value of the image in a variable and then write it back after overwriting the file. Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/71685-solved-need-to-swap-two-files-they-are-photos-being-swapped-is-there-a-command/#findComment-360885 Share on other sites More sharing options...
spdwrench Posted October 3, 2007 Author Share Posted October 3, 2007 I figured it out using the exisiting script functions swaps the 2 files and updates the description in the database I had to swap thumbs and the reg pic else if ($action == "makeprimary") { $f = f(q("SELECT * FROM dt_photos WHERE member_id=$fMember[id]")); $g = "filename_$photo_id"; @rename("photos/$fPhoto[$g]","photos/swap.tmp"); $photo_fname = substr($fPhoto[$g],0,strrpos($fPhoto[$g],".")); $photo_ftype = substr($fPhoto[$g],strrpos($fPhoto[$g],".")); @rename("photos/".$photo_fname.'_thumb'.$photo_ftype,"photos/swapthumb.tmp"); // Above changes name of select photo to temp files swap and swapthumb $prg="filename_1"; @rename("photos/$fPhoto[$prg]","photos/$fPhoto[$g]"); $nphoto_fname = substr($fPhoto[$prg],0,strrpos($fPhoto[$prg],".")); $nphoto_ftype = substr($fPhoto[$prg],strrpos($fPhoto[$prg],".")); @rename("photos/".$nphoto_fname.'_thumb'.$nphoto_ftype,"photos/".$photo_fname.'_thumb'.$photo_ftype); // write from primary to new spot in database $desc = "description_1"; $sdesc= "description_$photo_id"; q("UPDATE dt_photos SET description_$photo_id = '$f[$desc]' WHERE member_id='$fMember[id]'"); q("UPDATE dt_photos SET description_1 = '$f[$sdesc]' WHERE member_id='$fMember[id]'"); // end of description swap // above changes primary into posistion of swapped photo also thumb @rename("photos/swap.tmp","photos/$fPhoto[$prg]"); @rename("photos/swapthumb.tmp","photos/".$nphoto_fname.'_thumb'.$nphoto_ftype); } // added above I always feel like I wont get it and at the last minute falls together easily sometimes when I think to hard it throws me off Paul Quote Link to comment https://forums.phpfreaks.com/topic/71685-solved-need-to-swap-two-files-they-are-photos-being-swapped-is-there-a-command/#findComment-361028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.