首页 \ 问答 \ PHP chmod和file_get_content权限问题(PHP chmod and file_get_content permission problem)

PHP chmod和file_get_content权限问题(PHP chmod and file_get_content permission problem)

在PHP中,我正在抓取远程图像:

$img = file_get_contents("http://example.com/image.jpg");
file_put_contents("../testdir/photo.jpg",$img);

除非testdir设置为chmod 0777,否则我会收到Permission Denied错误。其中,我尝试使用PHP,然后将其设置回0755:

chmod("../testdir/", 0777);
$img = file_get_contents("http://example.com/image.jpg");
file_put_contents("../testdir/photo.jpg",$img);
chmod("../testdir/", 0755);

但我得到了不允许的操作是否有安全,可行的替代方案?

谢谢!


In PHP, I'm grabbing remote images with:

$img = file_get_contents("http://example.com/image.jpg");
file_put_contents("../testdir/photo.jpg",$img);

I get a Permission Denied error unless testdir is set to chmod 0777. Which, I tried to do with PHP and then set it back to 0755:

chmod("../testdir/", 0777);
$img = file_get_contents("http://example.com/image.jpg");
file_put_contents("../testdir/photo.jpg",$img);
chmod("../testdir/", 0755);

but I got Operation Not Permitted Is there a safe, working alternative?

Thanks!


原文:https://stackoverflow.com/questions/7586337
更新时间:2022-09-22 20:09

最满意答案

我测试了您上面提供的代码,但没有看到任何问题。 这让我相信文件中的数据可能有问题。 你能粘贴文件数据吗? (制表符分隔数据)

更新 - 我发现了问题 - 怀疑是这是一个数据问题(也涉及一些次要的代码更新)。 进行以下更改 -

1)打开文件时使用适当的编码,我使用utf-16。

2)在您共享的数据文件的末尾,它包含文本 - “(72413行受影响)”以及几个新行字符。 因此,您有2个选项,手动清理数据文件,或更新代码以忽略“(72413行受影响)”和“\ n”字符。

希望有所帮助。


I tested the code that you provided above, and didn't see any issues. That leads me to believe that there might be something wrong with the data that you have in the file. Could you paste the file data? (the tab delimited data)

UPDATE - I found the issue - as suspected, it was a data issue (there is a minor code update involved too). Make the following changes -

1) When opening the file use the appropriate encoding, I used utf-16.

2) At the end of the data file that you shared, it contains the text - "(72413 row(s) affected)" along with a couple of new line characters. So, you have 2 options, either manually cleanup the data file, or update the code to ignore the "(72413 row(s) affected)" & "\n" characters.

Hope that helps.

相关问答

更多
  • 绘制List的假设图片可能会有所帮助。 这是一个可能的外部列表,其内容如下: 0: [] 1: [a, b, c] 2: [d, e] 3: [] 等等 因此,它与2D阵列不同,因为没有统一的列大小。 所以你可以看到,索引0的外部列表是空的,索引1,有一个包含3个项目的列表,等等。 鉴于此,要迭代List> ,您还必须每次都检查内部列表的大小: for (int x = 0; x < list.size(); x++) { for (int y = 0; y < list ...
  • 那是因为你说过你的String数组的限制是17, public String[][] junior = new String[17][1]; 但最终你的代码 while (scanner.hasNextLine()){ InputLine2 = scanner.nextLine(); String[] InArray = InputLine2.split (","); for (int x=0; x< InArray.length; x++){ junior [Row ...
  • 很可能你的临时数组大于cell.x中存在的任何值。 它也可能是cell.x太大而你想要cell.x -1 Most likely your temp array is larger than whatever value exists in cell.x. Its also possible that cell.x is one too big and you want cell.x -1
  • 我测试了您上面提供的代码,但没有看到任何问题。 这让我相信文件中的数据可能有问题。 你能粘贴文件数据吗? (制表符分隔数据) 更新 - 我发现了问题 - 怀疑是这是一个数据问题(也涉及一些次要的代码更新)。 进行以下更改 - 1)打开文件时使用适当的编码,我使用utf-16。 2)在您共享的数据文件的末尾,它包含文本 - “(72413行受影响)”以及几个新行字符。 因此,您有2个选项,手动清理数据文件,或更新代码以忽略“(72413行受影响)”和“\ n”字符。 希望有所帮助。 I tested the ...
  • 正如@Steven Doggart所说(并且在答案中打了我一分钟)你正在声明一个阵列,但你没有给出尺寸长度。 你有两个选择: 在声明中指定数组维度大小 或使用Redim设置数组的(维度)大小 在您的情况下,一个解决方案可能如下所示: Dim dataArray(,) As Array = New Array(3, DT.Rows.Count) {{}} 或者像这样: Dim dataArray(,) As Array = New Array(,) {{}} Redim dataArray(3, DT.Ro ...
  • 在next()你一直在递增row但是没有故障安全索引超出row检查row因为有col ,所以不能保证row超过大于8的值,即9。 因此,确保在行resi(matrica2,row + 1, 0); )中递增( row+1 )之前检查row是否小于8 resi(matrica2,row + 1, 0); 。 private static void next(int [][] matrica2,int row, int col) { if (col 8) { resi(matrica2,row, co ...
  • 你使用[[AnyObject]]()实例化了一个二维数组,但它仍然是空的,这意味着你在self.internalData[0]没有任何内容可以追加。 你可以做很多事情来处理这个问题,但是如果你知道你将在self.internalData有3个数组,你可以像这样实例化每个内部数组: self.internalData = [[AnyObject](), [AnyObject](), [AnyObject]()] 现在你在self.internalData[0]上有一个空数组可以追加项目。 但是,似乎如果你已 ...
  • 你在isSolvable的内部循环中有一个拼写错误: for (int j = 0; i < copy[i].length; j++){ ^ | should be j 应该: for (int j = 0; j < copy[i].length; j++){ You have a typo in the inner loop of isSolvable: for (int j = 0; i < copy[i].len ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)