PHP file extension

I am trying to modify the exenstion of a file, but whenever I make a file, it seems to be damaged.

$oldFileName = $targetDir . DIRECTORY_SEPARATOR . $fileName; $newString = preg_replace('"\.tmp$"', '.jpg', $oldFileName); rename($oldFileName, $newString); 

The code works and changes the extension, but still the file appears to be damaged when it is downloaded.

The extension is .tmp and I am trying to change it to .jpg.

If I download .tmp and manually change it to .jpg, this works, but not when PHP does it.

Does anyone know why this might happen?

Thanks!

0
source share
1 answer

try it

 <?php $file = 'example.txt'; $newfile = 'example.txt.bak'; //new file with extension if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } ?> 
+5
source

All Articles