我有一個form input type =「file」元素,它接受一個文件。當我上傳它並將其傳遞到服務器端的PHP腳本。如何在php中以字節爲單位上載文件
如何以字節爲單位寫入存儲在$ _FILES [「file」] [「tmp_name」]中的臨時文件? 下面的代碼不起作用。它似乎寫在請求的最後。如果因爲例如連接丟失,我想看看是否40%是完整的,以便我可以恢復它。
任何指針?
$target_path = "uploads/";
$target_path = $target_path . basename($name);
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
// Open temp file
$out = fopen($target_path, "wb");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen($_FILES['file']['tmp_name'], "rb");
if ($in) {
while ($buff = fread($in, 4096))
fwrite($out, $buff);
}
fclose($in);
fclose($out);
}
}
PHP上傳不起作用。 – ceejayoz