亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

建立指定大小的php文件
P粉221046425
P粉221046425 2023-10-26 14:03:01
0
2
745

如何在 PHP 中建立給定大小的檔案(無論內(nèi)容為何)?

我必須建立一個大於 1GB 的檔案。最大約 4-10GB

P粉221046425
P粉221046425

全部回覆(2)
P粉561323975

如果檔案的內(nèi)容不相關(guān),則只需填充它 - 但請確保不會產(chǎn)生太大而無法保存在記憶體中的變數(shù):

<?php
$fh = fopen("somefile", 'w');
$size = 1024 * 1024 * 10; // 10mb
$chunk = 1024;
while ($size > 0) {
   fputs($fh, str_pad('', min($chunk,$size)));
   $size -= $chunk;
}
fclose($fh);

如果檔案必須被其他東西讀取 - 那麼你如何做到這一點取決於需要讀取它的其他東西。

C.

P粉039633152

您可以使用fopenfseek

define('SIZE',100); // size of the file to be created.
$fp = fopen('somefile.txt', 'w'); // open in write mode.
fseek($fp, SIZE-1,SEEK_CUR); // seek to SIZE-1
fwrite($fp,'a'); // write a dummy char at SIZE position
fclose($fp); // close the file.

執(zhí)行時:

$ php a.php

$ wc somefile.txt
  0   1 100 somefile.txt
$
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板