html - how find file name in a server source using php -
i have link.when clicking on link pdf file downloaded. trying save file folder. static name getting saved,but want save actual name,is possible? if knows please me.
sample url:- http://www.intercoat.de/index.php?option=com_jdownloads&itemid=206&task=finish&cid=341&catid=178&lang=en
am attaching code below. have array of links above sample link fetching array
foreach($li $lm) { $i++; $file_info = new finfo(fileinfo_mime_type); $mime_type = $file_info->buffer(file_get_contents($lm)); if($mime_type=='application/pdf') { echo $lm.$i.'<br>'; $filecontent = file_get_contents($lm); file_put_contents('./uploads/myfile'.$i.'.pdf', $filecontent); } }
now files not saving exact name,it saves myfile1,myfile2 ..etc cant take base name because file name not in url.that urls source of file. knows please help
try this
foreach($li $lm) { $i++; $file_info = new finfo(fileinfo_mime_type); $mime_type = $file_info->buffer(file_get_contents($lm)); if($mime_type=='application/pdf') { echo $lm.$i.'<br>'; $filecontent = file_get_contents($lm); $actual_name = basename($lm); file_put_contents('./uploads/'.$actual_name', $filecontent); } }
Comments
Post a Comment