我可以将文件保存到wordpress中,但不会显示 [英] I can save the file into wordpress but it does not show it

查看:80
本文介绍了我可以将文件保存到wordpress中,但不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机上运行wordpress,我可以使用以下代码将文件成功保存到wordpress的上传目录中,但是wordpress不会在其媒体库中显示它们,尽管它仅显示了我使用其上传功能上传的文件.

I am running wordpress on localhost, I can successfully save files into upload directory of wordpress using the following code, but wordpress does not show them in its media library, although it shows just those that I upload using its upload feature.

require("/Applications/MAMP/htdocs/wordpress/wp-load.php");

$Addr = "http://www.xxx.com" . $Addr;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $Addr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);

ini_set( 'display_errors', TRUE );
error_reporting( E_ALL );

$upload_dir = wp_upload_dir(); 
$location= $upload_dir['basedir']. "/" . "a.jpg";


file_put_contents($location, $output);
echo 'Photo is uploaded';

当我转到以下地址时,我可以在那里看到照片.

When I go to following address I can see the photos there.

http://localhost:8888/wordpress/wp-content/uploads/

我什至手动复制了一个文件,但它也没有显示该文件,但是当我使用wordpress本身上传同一文件时,将显示该文件.

I even copied a file manually but it does not show that one as well but when I upload the same file using wordpress itself the file will be shown.

推荐答案

似乎是权限问题,请尝试使用chmod设置644:

Seems a permission problem, try set 644 with chmod:

file_put_contents($location, $output);
chmod($location, 0644); // <--- new code

这篇关于我可以将文件保存到wordpress中,但不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆