0
$ext = pathinfo($url, PATHINFO_EXTENSION);
if ( $ext == 'pdf' || $ext == 'doc' || $ext == 'docx') {
  file_put_contents('product-docs/'.$slug.'-'.$r.'.'.$ext, $url);
}

我希望此代码能够下载文档,而是使用正确的扩展名保存文件,但在编辑器中打开它会显示文件的内容是 URL 本身。

4

1 回答 1

0

这有效:

if ( $ext == 'pdf' || $ext == 'doc' || $ext == 'docx') {
  $doc = file_get_contents($url);
  file_put_contents('product-docs/'.$slug.'-'.$r.'.'.$ext, $doc);
}
于 2016-12-09T03:40:13.107 回答