ftruncate
-
We use the
ftruncatefunction in PHP to truncate a file to a given length.PHP
$f = fopen('/path/to/foobar', 'w') ftruncate($f, 10); fclose($f);
The same task can be accomplished in Ruby with the
File#truncatemethod:Ruby
File.open('/path/to/foobar', 'w') do |f| f.truncate(10) end
Ruby also provides the
File.truncateclass method for convenience. It allows you to truncate a file without opening it yourself.Ruby
File.truncate('/path/to/foobar', 10)
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

