Frage

I have this code:

// Build the path where I want to save the file;
$filePath="uploads/image.jpeg";
/*
 * Open an input stream relative to $_FILES['file']['tmp_name'] 
 * and write it in an output stream relative to $filePath;
 */
writeFile($filePath);

echo "Before resizing: ".filesize($filePath)." bytes";

/*
 * Create a resized version of the image using imagecopyresampled();
 */
$imageResized = resizeImage($filePath);
/*
 * Actually write the image to the same location of the original;
 */
imagejpeg($imageResized, $filePath);

echo "After resizing: ".filesize($filePath)." bytes";

Now the fact is that the ehoes give me the same exact filesize, while actually in the file explorer the filesize after resizing is much lower! How do I get the correct file size after resizing?

War es hilfreich?

Lösung

See the manual on filesize:

Note: The results of this function are cached. See clearstatcache() for more details.

So use a clearstatcache() before the second filesize call

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top