开发者

Moving a file with a specific string in the filename [closed]

It's difficult to tell what is being asked here. This question is ambig开发者_如何转开发uous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜