TAILIEUCHUNG - Phát triển web với PHP và MySQL - p 40

Interacting with the File System and the Server CHAPTER 16 365 Creating, Deleting, and Moving Files You can use the file system functions to create, move, and delete files. First, and most simply, you can create a file, or change the time it was last modified, using the touch() function. This works similarly to the UNIX command touch. The function has the following prototype: int touch (string file, [int time]) 16 INTERACTING WITH THE FILE SYSTEM AND THE SERVER If the file already exists, its modification time will be changed either to the current time, or the time given in the second parameter if it is specified | Interacting with the File System and the Server 365 Chapter 16 Creating Deleting and Moving Files You can use the file system functions to create move and delete files. First and most simply you can create a file or change the time it was last modified using the touch function. This works similarly to the UNIX command touch. The function has the following prototype int touch string file int time If the file already exists its modification time will be changed either to the current time or the time given in the second parameter if it is specified. If you want to specify this it should be given in time stamp format. If the file doesn t exist it will be created. You can also delete files using the unlink function. Note that this function is not called delete there is no delete. You use it like this unlink filename This is one of the functions that doesn t work with the Win32 build. However you can delete a file in Windows with system del You can copy and move files with the copy and rename functions as follows copy source_path destination_path rename oldfile newfile You might have noticed that we used copy in Listing . The rename function does double duty as a function to move files from place to place because PHP doesn t have a move function. Whether you can move files from file system to file system and whether files are overwritten when rename is used is operating system dependent so check the effects on your server. Also be careful about the path you use to the filename. If relative this will be relative to the location of the script not the original file. Using Program Execution Functions We ll move away from the file system functions now and look at the functions that are available for running commands on the server. This is useful when you want to provide a Web-based front end to an existing command linebased system. For example we have used these commands to set up a front end for the mailing list manager ezmlm. We will use these again when we

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.