密码保护目录但仍允许在主页上使用

时间:2012-07-08 17:07:18

标签: php file

我正在尝试将图像移动到服务器端的tmp目录,然后从tmp文件夹将其发送到客户端,但事情并不是很有效。这就是我现在所拥有的。

//this is where the image resides permanently
$imgdirectory = "../" . $ms . "msimages/" . $img_filename;
//here I'm trying to get the contents of the img from its permanent location    
$content = file_get_contents($imgdirectory);
//here I'm trying to create a new temporary file
file_put_contents('/tmp/img.jpg', $content);

...

echo "img {background:url(\"/tmp/img.jpg\")-" . $xleft . "px -" . $ytop . "px";}"; this is the css trying to use file that is supposed to be in the temp folder

这是我在页面加载时获得的css输出

img#{width:631px;height:453px;background:url("/tmp/img.jpg")-144px -112px;}

但遗憾的是,/tmp/img.jpg没有文件,因此某些内容无法与file_put_contents 404 image not found

一起使用

顺便说一句,我在/ tmp中没有收到put contents权限的任何错误,

感谢任何建议。

1 个答案:

答案 0 :(得分:2)

使用复制而不是读写文件

 bool copy ( string $source , string $dest [, resource $context ] )

file_put_contents('/tmp/img.jpg', $content);

将它放在root tmp目录下,而不是在你的站点tmp目录中。

尝试

file_put_contents($_SERVER["DOCUMENT_ROOT"] . 'tmp/img.jpg', $content);
相关问题