Jump to content

[SOLVED] Need to swap two files.... They are photos being swapped. Is there a command?


spdwrench

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.