Php file programming (IV)-file copy folder creation
// $ File_path = iconv ("UTF-8", "gb2312", "C: \ Documents and Settings \ All Users \ Documents Ents \ My Pictures \ sample image \ complete to .jpg ");
- /* If (! Copy ("C :\\ Winter.jpg", "D :\\ aa.jpg ")){
- Echo "error ";
- } Else {
- Echo "OK ";
- }
- */
// Transcode Chinese. Otherwise, an error is returned.
- $ File_path = iconv ("UTF-8", "gb2312", "C: \ Documents and Settings \ All Users \ Documents Ents \ My Pictures \ sample image \ Winter.jpg ");
- If (! Copy ($ file_path, "D: \ baa.jpg ")){
- Echo "error ";
- } Else {
- Echo "OK ";
- }
- ?>
2. create and delete folders, create and delete files
/**
- * Create and delete files and folders
- * Edit bbs.it-home.org
- */
- // ************ Create a folder ***********
- /* If (mkdir ("d:/pwmm ")){
- Echo "OK ";
- } Else {
- Echo "error ";
- }
- */
- // Determine whether the file name contains is_dir ("d:/pwmm") | file_exists ("d:/pwmm ")
- /*
- If (! Is_dir ("d:/pwmm ")){
- If (mkdir ("d:/pwmm ")){
Echo "folder created successfully ";
- } Else {
Echo "folder creation failed ";
- }
- } Else {
- Echo "the folder already exists ";
- }
- */
// ********** Create a multi-level directory ************
/* $ Path = "D:/pwm/aaa/bbb/ccc ";
- If (! Is_dir ($ path )){
If (mkdir ($ path, 0777, true )){
Echo "folder created successfully ";
- } Else {
Echo "folder creation failed ";
- }
- } Else {
- Echo "the folder already exists ";
- }
- */
- // ********** Delete a directory
- // If the directory contains a file or directory, the deletion fails.
- /* If (rmdir ("d:/test11 ")){
- Echo "OK ";
- } Else {
- Echo "error ";
- }
- */
-
- // ************* Create a file
- // Create test.txt in the directory test2of drive D.
- /* $ Path = "d:/test2/test.txt ";
- $ Fp = fopen ($ path, "w + ");
- Fwrite ($ fp, "how are you ");
- Fclose ($ fp );
- Echo "OK ";
- */
// ************** Delete an object
- $ Path = "d:/test2/test.txt ";
- If (is_file ($ path )){
- If (unlink ($ path )){
- Echo "deleted successfully ";
- } Else {
- Echo "failed to delete ";
- }
- } Else {
- Echo "the file does not exist ";
- }
- ?>
|