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
最满意答案
我测试了您上面提供的代码,但没有看到任何问题。 这让我相信文件中的数据可能有问题。 你能粘贴文件数据吗? (制表符分隔数据)
更新 - 我发现了问题 - 怀疑是这是一个数据问题(也涉及一些次要的代码更新)。 进行以下更改 -
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.
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
绘制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 ...
-
使用csv文件填充2d数组时,我的数组索引超出了范围(My array index is out of bounds when populating a 2d array using a csv file)[2023-12-08]
那是因为你说过你的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 ...
-
数组索引超出范围?(Array index out of bounds? How?)[2022-07-26]
在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 ... -
2D数组:索引超出范围(2D arrays: Index out of range)[2024-03-06]
你使用[[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 ...