$ext = pathinfo($url, PATHINFO_EXTENSION);
if ( $ext == 'pdf' || $ext == 'doc' || $ext == 'docx') {
file_put_contents('product-docs/'.$slug.'-'.$r.'.'.$ext, $url);
}
我希望此代码能够下载文档,而不是使用正确的扩展名保存文件,但在编辑器中打开它会显示文件内容是URL本身。
答案 0 :(得分:0)
这有效:
if ( $ext == 'pdf' || $ext == 'doc' || $ext == 'docx') {
$doc = file_get_contents($url);
file_put_contents('product-docs/'.$slug.'-'.$r.'.'.$ext, $doc);
}