Hướng dẫn how to create temporary file in php - cách tạo file tạm trong php

(Php 4, Php 5, Php 7, Php 8)

TMPFILE - Tạo một tệp tạm thờiCreates a temporary file

Sự mô tả

tmpfile (): tài nguyên | sai(): resource|false

Tệp được tự động xóa khi đóng (ví dụ: bằng cách gọi fclose () hoặc khi không có tài liệu tham khảo còn lại cho xử lý tệp được trả về bởi tmpfile ()) hoặc khi tập lệnh kết thúc.fclose(), or when there are no remaining references to the file handle returned by tmpfile()), or when the script ends.

Thận trọng

Nếu tập lệnh chấm dứt bất ngờ, tệp tạm thời có thể không bị xóa.

Thông số

Chức năng này không có tham số.

Trả về giá trị

Trả về một tay cầm tệp, tương tự như tệp được trả về bởi fopen (), cho tệp mới hoặc false về lỗi.fopen(), for the new file or false on failure.

Ví dụ

Ví dụ #1 tmpfile () ví dụtmpfile() example

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>

Ví dụ trên sẽ xuất ra:

Xem thêm

  • Tempnam () - Tạo tệp có tên tệp duy nhất
  • SYS_GET_TEMP_DIR () - Trả về đường dẫn thư mục được sử dụng cho các tệp tạm thời

Giám mục ¶

4 năm trước

To get the underlying file path of a tmpfile file pointer:

$file = tmpfile();
$path = stream_get_meta_data($file)['uri']; // eg: /tmp/phpFx0513a

Chris [at] PureFormSolutions [dot] com ¶

17 năm trước

I found this function useful when uploading a file through FTP. One of the files I was uploading was input from a textarea on the previous page, so really there was no "file" to upload, this solved the problem nicely:

    # Upload setup.inc
   
$fSetup = tmpfile();
   
fwrite($fSetup,$setup);
   
fseek($fSetup,0);
    if (!
ftp_fput($ftp,"inc/setup.inc",$fSetup,FTP_ASCII)) {
        echo
"
Setup file NOT inserted

"
;
    }
   
fclose($fSetup);
?>

The $setup variable is the contents of the textarea.

And I'm not sure if you need the fseek($temp,0); in there either, just leave it unless you know it doesn't effect it.

Ẩn danh ¶

6 năm trước

Since this function may not be working in some environments, here is a simple workaround:

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
0

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
1

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
2

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
3

thần thánh76 tại gmail dot com ¶

2 năm trước

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
5

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
6

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
7

Elm tại gmail dot nospamplease dot com ¶

3 năm trước

$temp tmpfile();
fwrite($temp"writing to tempfile");
fseek($temp0);
echo 
fread($temp1024);
fclose($temp); // this removes the file
?>
9

oremanj tại gmail dot com

15 năm trước

To get the underlying file path of a tmpfile file pointer:0

To get the underlying file path of a tmpfile file pointer:1

To get the underlying file path of a tmpfile file pointer:2

ssandor ¶

9 năm trước

To get the underlying file path of a tmpfile file pointer:4

Tệp TMP trong PHP là gì?

Định nghĩa và cách sử dụng. Hàm tmpfile () tạo một tệp tạm thời có tên duy nhất ở chế độ read-write (w+). Lưu ý: Tệp được tự động xóa khi đóng, với fclose () hoặc khi tập lệnh kết thúc.creates a temporary file with a unique name in read-write (w+) mode. Note: The file is automatically removed when closed, with fclose() or when the script ends.

PHP lưu trữ các tệp tạm thời ở đâu?

PHP lưu trữ tất cả các tệp tạm thời, bao gồm các tệp được tải lên, trong thư mục tệp tạm thời như được chỉ định trong php.ini.temporary files directory as specified in the php. ini.

Phần mở rộng tệp TMP là gì?

Tệp TMP đề cập đến sao lưu tạm thời, lưu trữ hoặc hệ thống tệp khác được tạo bởi chương trình phần mềm.Nó đôi khi được tạo ra dưới dạng một tệp vô hình và thường xuyên bị phá hủy khi chương trình bị bỏ.Các tệp TMP cũng có thể được sử dụng để lưu trữ thông tin tạm thời trong khi một tệp mới đang được xây dựng.a transitory backup, storage, or other file system generated by a software program. It is occasionally created as an invisible file and is frequently destroyed when the program is quit. TMP files can also be used to temporarily store information while a new file is being constructed.

Trả về tệp TMP là gì?

Hàm tmpfile () trả về một con trỏ luồng, nếu thành công.Nếu nó không thể mở tệp, nó sẽ trả về một con trỏ null.Ở cuối bình thường (thoát ()), các tệp tạm thời này được xóa.Trên hệ thống quản lý dữ liệu, hàm tmpfile () tạo ra một tệp mới được đặt tên là QTEMP/QACXXXXXXXX.a stream pointer, if successful. If it cannot open the file, it returns a NULL pointer. On normal end ( exit() ), these temporary files are removed. On the Data Management system, the tmpfile() function creates a new file that is named QTEMP/QACXxxxxxx.