PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
My problem at this point is I have been told by users on this site that you can use basename() to create files within a directory, and I now know dirname() is akin to basename. If the above is true, and I understood fully, then how would one go about using it. I will attach a sample code I typed up now and pray that its at least generally what I need.
What's improper, your code? Likely, it is unless you have "foo.php" as a directory for some reason.
akimm wrote:If so could you suggest any functions that could achieve my intended goal?
I'm not sure what your goal is, but your code snippet above would suggest using dirname() over basename() in this case. However your code has a security hole: you've used a post variable without validation and verification. This could potentially be used to corrupt other files in your webspace.
Well thank you for the security suggestion. I am just making this program for my own usage, really just to practice. But if I ever actually use this I will certainly add some validation as you've suggested, because I never actually considered that.
My intended goal is to create files on the fly. Like if I put my name sean down, I'd like the program to take the POST variable and write sean.txt, this file would contain an article I wrote so I can have an interface for my articles, so I don't need to use as much html, I can automate it so to speak.
I know as of now its not accepting the _$POST['artice'] I just need to write that part yet, but my chief concern is discovering which tool to use for this problem.
My intended goal is to create files on the fly. Like if I put my name sean down, I'd like the program to take the POST variable and write sean.txt, this file would contain an article I wrote so I can have an interface for my articles, so I don't need to use as much html, I can automate it so to speak.
I know as of now its not accepting the _$POST['artice'] I just need to write that part yet, but my chief concern is discovering which tool to use for this problem.
Basically I am not familier enough with either one to telll you exactly which I need. Although what I want to be able to do is write files on the fly. like if I enter an article in the form and $_POST['article'] = sean's article or whatever it may be.
This file doesn't exist, so I don't think these functions are what I need. the file will be created when I select a title for the article, and submit it. Upon doing so I want to write it to my directory, then i can include it with a simple line of PHP code.
I'm not sure if it was the intended result, but thats how it acted on my server. I checked my directory, it did not create the dirname if it was meant to, it didn't as it is now.
I'm not sure if it was the intended result, but thats how it acted on my server.
Yes, that is exactly how it should work: dirname() give the directory portion of the string and basename() gives the filename portion of the string.
akimm wrote:I checked my directory, it did not create the dirname if it was meant to, it didn't as it is now.
It is not meant to create directories. The dirname() and basename() functions only deal with extracting sub-strings from full file path strings. They do not do anything to the file system. There are other functions for those functions (see the PHP manual for Filesystem functions).
Can those other functions do the task I need? To create files when they're not there to begin with. Because, I know for sure we can append to files, but that will do me no good.