Moving a file with a specific string in the filename [closed]
I have a series of pdfs that contain an Id in the filename. I also have an excel file which I am able to read and get ids from. I want to loop through all ids in the file and move any pdf that includes one of the ids in the filename to another folder.
$file = fopen($_FILES['uploadfile']['tmp_name'],"r");
while (($data = fgetcsv($file, 15000, ",")) !== FALSE) {
//need something that does it here
}
You can use rename to move a file. To check if it exists or not you can use file_exists. Get the ID
, append .pdf
to it and check it if there.
You need to give the path to the file, when checking and moving
This is if Id is the file name.. ie your file name is "id.pdf".
To check for a id in the filename (similar to pattern matching), use glob to get all files in the directory with .pdf
, then check if it exists using foreach
and preg_match
精彩评论