Question

Im trying to make a program with winbinder that converts .iwd to .zip (its possible to do it just by renaming the .iwd to .zip) and i need to know how to take my varible that contains the file and make it overwrite the extension with a .zip

case 11:
            $filename = $GLOBALS["orig_filename"];
            $withoutExt = preg_replace("/\\.[^.\\s]{3,4}$/", "", $filename);
            $filename_with_zip = $filename."zip";
            echo shell_exec("rename ,"$filename" ,"$filename_with_zip"");
            echo $filename_with_zip;
        break;
Was it helpful?

Solution

Code:

Kudos to Almis for the original awnser, modified to fit your use a bit more and explained.

case 11:
     $iwd = $GLOBALS["orig_filename"];
     $zip = str_replace('.iwd', '.zip', $iwd);
     rename($iwd, $zip);
break;


Explanation:

First of all, don't use shell_exec() for an already built in PHP function rename, usage here php.net/rename.

Second of all, str_replace() provides the ability to replace an param 1 with param 2 www.php.net/manual/en/function.str-replace.php

And lastly, don't use globals they can make problems harder to diagnose among other things ref. https://stackoverflow.com/questions/1557787/are... If you still decide to use them, I find it better to use global $value before needing the value in a separate function.

OTHER TIPS

You can change a file extension like that

$iwd = "C:/path/to/myfile.iwd";
$zip = str_replace('.iwd', '.zip', $iwd);
rename($iwd, $zip);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top