image - Get first file in directory PHP -


i want first file in directory using php.

i trying make function users on website can change profile picture. show profile picture on profile page want first image in profile picture folder. want image have uploaded, regardless of file type. have made when upload new picture old 1 deleted, 1 file in folder. how do this?

you can first file in directory this

$directory = "path/to/file/"; $files = scandir ($directory); $firstfile = $directory . $files[2];// because [0] = "." [1] = ".."  

then open fopen() can use w or w+ modes:

w open writing only; place file pointer @ beginning of file , truncate file 0 length. if file not exist, attempt create it.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -