Home arrow PHP arrow Page 3 - Stream Me Up, Scotty (part 2)

To Create And Destroy - PHP

You've already seen how PHP4's FTP functions can help youinteract with files on a remote server. In this article, learn how to usePHP's other file and directory manipulation functions, and build anequivalent application that demonstrates the difference between the twoapproaches.

TABLE OF CONTENTS:
  1. Stream Me Up, Scotty (part 2)
  2. Looking Around
  3. To Create And Destroy
  4. Upsa-daisy!
  5. Remote Control
  6. The Application
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 2
November 29, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Next up, a little file and directory manipulation. If you'd like to create directories, PHP provides the mkdir() function, which accepts a file path and a mode as parameters, So, if I wanted to create a directory called "/tmp/me" with permissions 755, I would use something like this:

<? if (mkdir ("/tmp/me", 0755)) { echo "Successful!"; } else { echo "Unsuccessful"; } ?>
And to reverse the process, there's always the rmdir() function, used to delete directories. Note that rmdir() will fail if the directory permissions don't allow deletion, or if the directory contains one or more files.

<? if (rmdir ("/tmp/me")) { echo "Successful!"; } else { echo "Unsuccessful - check permissions and ensure directory is empty!"; } ?>
You can delete files with the unlink() function, which accepts a filename as parameter. <? if (unlink("/tmp/dummyfile")) { echo "Successful!"; } else { echo "Unsuccessful!"; } ?>

 And finally, you can copy files with the copy() function, 

<? if (copy("/tmp/source", "/tmp/destination")) { echo "Successful!"; } else { echo "Unsuccessful!"; } ?>
and rename (or move) them with the rename() function.

<? if (rename("/tmp/oldfile", "/etc/newfile")) { echo "Successful!"; } else { echo "Unsuccessful!"; } ?>


This article copyright Melonfire 2000. All rights reserved.

 
 
>>> More PHP Articles          >>> More By Vikram Vaswani, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: