-
-
Save kongondo/6599575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// stripped down code | |
$old_name = 'lizard.jpg'; | |
$new_name = 'wizard'; | |
$p = $pages->find("image.data=$old_name")->first(); | |
$p->of(false); // outputformatting off, single and multiple image fields are from now on wire array's | |
$img = $p->image->find("name=$old_name")->first(); | |
$new_img = $p->image->path . $new_name .".". $img->ext; | |
// copy and rename | |
copy($img->filename, $new_img); | |
// remove old, add new image to page | |
$p->image->remove($img); // orig, will get deleted | |
$p->image->add($new_img); // new | |
$p->save(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// yet another example using PW pagefile->rename() | |
$old_name = 'wizard.jpg'; | |
$new_name = 'lizard'; | |
$p = $pages->get("image.data=$old_name"); | |
$p->of(false); // outputformatting off, single and multiple image fields are from now on wire array's | |
// get the image and the extension | |
$image = $p->image->find("name=$old_name")->first(); | |
$ext = $image->ext; | |
$newFilename = $new_name . "." . $ext; | |
$p->image->trackChange("basename"); | |
$image->removeVariations(); | |
$image->rename($newFilename); | |
$p->save("image"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$old_name = 'lizard.jpg'; | |
$new_name = 'wizard'; | |
$p = $pages->find("image.data=$old_name")->first(); | |
$p->of(false); // outputformatting off, single and multiple image fields are from now on wire array's | |
$path = $p->image->path; | |
$page_image = $p->image->find("name=$old_name")->first(); // find the image | |
$ext = $page_image->ext; | |
$orig_image = $page_image->filename | |
$new_image = $path . $new_name . "." . $ext; | |
echo "orig: " . $orig_image . "<br/>"; | |
echo "path: " . $path . "<br/>"; | |
echo "ext: " . $ext . "<br/>"; | |
echo "new: " . $new_image . "<br/>"; | |
// copy and rename | |
copy($orig_image, $new_image); | |
// remove old, add new image to page | |
$p->image->remove($page_image); // orig, will get deleted | |
$p->image->add($new_image); // new | |
$p->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment