2012-07-08 101 views
2

我试图将图像移动到服务器端的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_contents404 image not found

BTW工作,我在/ tmp,

中没有收到关于put contents权限的任何错误非常感谢。

+0

如果你没有给脚本读取权限,或访问权限,可以返还找不到文件。 – 2012-07-08 17:09:44

回答

2

使用副本而不是读取和写入文件

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

而且

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

就会把它根tmp目录下的不是在你的网站tmp目录。

尝试

file_put_contents($_SERVER["DOCUMENT_ROOT"] . 'tmp/img.jpg', $content); 
+0

感谢您的建议。仍然没有工作 - 但我认为有很多因素会对我造成问题。复制似乎更好的路线,但我认为我的主要问题是权限。 – Jeff 2012-07-08 18:19:24