I'd like to add several lines to the beginning of a file, is there an easy way to do this?
Read the file.
Overwrite the file with the new lines
write out the rest of the file (that you'd just read)
Safer:
Create a new file, into which you write the new lines.
Read the original file
Write the contents of the original file to the new file.
Delete the original file
Rename the new file to the original name.
You may also think about appending lines to the end, and when reading, use $lines = array_reverse(file('file.ext')); Then it would look like you're appending to the beginning 🙂