首页 \ 问答 \ 无法删除使用PHP创建的目录或文件(也称为权限地狱)(Cannot delete directory or files created with PHP (a.k.a permissions hell))

无法删除使用PHP创建的目录或文件(也称为权限地狱)(Cannot delete directory or files created with PHP (a.k.a permissions hell))

这是独家新闻:我需要能够使用PHP脚本创建文件夹,并将图像文件上传到这些文件夹。 这是我的代码:

创建目录:

mkdir('[path]/images/foldername');  


正在上传图片:

if ($_FILES["file"]["error"] > 0 || $_FILES["file"]["type"] != "image/jpeg") // file must be valid and .jpg
{
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"] . '<br />';

    if(file_exists($path ."/" . $_FILES["file"]["name"]))
    {
        echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
        move_uploaded_file($_FILES["file"]["tmp_name"], $path ."/" . $_FILES["file"]["name"]);
        echo "Stored in: " . $path ."/" . $_FILES["file"]["name"];
    }
}

FTP编辑器给出了以下错误:

[L] DELE 20.jpg
[L] 550 Could not delete imagename.jpg: Permission denied

然后

[L] RMD foldername
[L] 550 Can't remove directory: Directory not empty

我尝试在FTP编辑器中更改权限,但出现此错误:

[L] SITE CHMOD 777 [路径] / foldername [L] 550无法更改[路径] / foldername上的电烫:不允许操作
我尝试使用SSH和Putty删除文件,但这也不起作用。

请帮帮我!


Here's the scoop: I need to be able to create folders using a PHP script and also to upload image files to those folders. Here is my code:

Creating a directory:

mkdir('[path]/images/foldername');  


Uploading Images:

if ($_FILES["file"]["error"] > 0 || $_FILES["file"]["type"] != "image/jpeg") // file must be valid and .jpg
{
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"] . '<br />';

    if(file_exists($path ."/" . $_FILES["file"]["name"]))
    {
        echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
        move_uploaded_file($_FILES["file"]["tmp_name"], $path ."/" . $_FILES["file"]["name"]);
        echo "Stored in: " . $path ."/" . $_FILES["file"]["name"];
    }
}

FTP editor gives these errors:

[L] DELE 20.jpg
[L] 550 Could not delete imagename.jpg: Permission denied

then

[L] RMD foldername
[L] 550 Can't remove directory: Directory not empty

I tried changing the permissions in my FTP editor, but got this error:

[L] SITE CHMOD 777 [path]/foldername [L] 550 Could not change perms on [path]/foldername: Operation not permitted
I tried using SSH with Putty to delete the file, but that did not work either.

Please help me!


原文:https://stackoverflow.com/questions/10660605
更新时间:2023-01-10 06:01

最满意答案

我不认为你想要什么可以用UpValuesUpValues )来完成,因为符号(标签)必须不比第一级更深才能定义工作。 此外,Mathematica中所需的语义有点不寻常,因为大多数Mathematica表达式是不可变的(不是L值),并且它们的部分不能被赋值。 我相信这段代码会做类似于你想要的东西:

Unprotect[Set];
Set[var_Symbol, rhs_] /; 
   MatchQ[Hold[var] /. OwnValues[var], Hold[_struct]] := Set[var[[1]], rhs];
Protect[Set];

例如:

In[33]:= var1 = struct[{1, 2}]

Out[33]= struct[{1, 2}]

In[34]:= var1 = "Success!"

Out[34]= "Success!"

In[35]:= var1

Out[35]= struct["Success!"]

但通常,不建议将DownValues添加到Set等重要命令,因为这可能会以微妙的方式破坏系统。

编辑

扩展一下你的尝试失败的原因:Mathematica使用参数保持机制( Hold* - 属性, 在此描述)实现流控制和赋值运算符。 该机制特别允许它模仿任务所需的传递引用语义。 但是,在你分配给var1Set不知道var1已经存储了什么,因为它只有符号var1 ,而不是它的值。 模式_struct不匹配,因为即使变量已经存储了一些structSet只有变量名。 为了匹配成功, Set内的变量将不得不评估为其值。 但是,那么价值是不变的,你不能指定它。 我建议的代码测试变量是否具有struct[something]形式的赋值,如果是,则修改第一部分( Part命令是一个例外,它可以修改L值表达式的一部分,前提是那些部分已经存在)。

您可以在许多地方阅读关于Hold* - 属性和相关问题的更多信息,例如这里这里


I don't think that what you want can be done with UpValues (alas), since the symbol (tag) must be not deeper than level one for definition to work. Also, the semantics you want is somewhat unusual in Mathematica, since most Mathematica expressions are immutable (not L-values), and their parts can not be assigned values. I believe that this code will do something similar to what you want:

Unprotect[Set];
Set[var_Symbol, rhs_] /; 
   MatchQ[Hold[var] /. OwnValues[var], Hold[_struct]] := Set[var[[1]], rhs];
Protect[Set];

For example:

In[33]:= var1 = struct[{1, 2}]

Out[33]= struct[{1, 2}]

In[34]:= var1 = "Success!"

Out[34]= "Success!"

In[35]:= var1

Out[35]= struct["Success!"]

But generally, adding DownValues to such important commands as Set is not recommended since this may corrupt the system in subtle ways.

EDIT

Expanding a bit on why your attempt failed: Mathematica implements flow control and assignment operators using the mechanism of argument holding (Hold* - attributes, described here). This mechanism allows it to, in particular, imitate pass-by-reference semantics needed for assignments. But then, at the moment when you assign to var1, Set does not know what is stored in var1 already, since it only has the symbol var1, not its value. The pattern _struct does not match because, even if the variable already stores some struct, Set only has the variable name. For the match to be successful, the variable inside Set would have to evaluate to its value. But then, the value is immutable and you can not assign to it. The code I suggested tests whether the variable has an assigned value that is of the form struct[something], and if so, modifies the first part (the Part command is an exception, it can modify parts of an L-value expression provided that those parts already exist).

You can read more on the topics of Hold* - attributes and related issues in many places, for example here and here

相关问答

更多
  • 赋值运算,先计算赋值号(也就是=号左边的,再赋值) 那么 a, b = b, a+b # 这种赋值,先计算等值 右边 那么 b=1 a+b=1 # 再赋值给a和b,那么 a=1, b=1而,下面的 a = b # 此时 b=1, 那么a=1 b = a+b # 那么 b=2明白了吧。
  • 回答你的问题: 想象a * b *是经常性的,是否有证据表明它是正常的? 不需要想象,表达式a*b*被称为r egular e xpression (re),正则表达式仅适用于常规语言。 如果语言不是常规的,那么正则表达式也是不可能的,如果语言是常规语言,那么我们总是可以用一些正则表达式来表示它。 是的, a*b*代表常规语言。 语言描述 :任何数字a后跟任意数字b ( 任意数字,我的意思是零(包括null ^ )或更多次数)。 一些示例字符串是: {^, a, b, aab, abbb, aabbb, . ...
  • 我不认为你想要什么可以用UpValues ( UpValues )来完成,因为符号(标签)必须不比第一级更深才能定义工作。 此外,Mathematica中所需的语义有点不寻常,因为大多数Mathematica表达式是不可变的(不是L值),并且它们的部分不能被赋值。 我相信这段代码会做类似于你想要的东西: Unprotect[Set]; Set[var_Symbol, rhs_] /; MatchQ[Hold[var] /. OwnValues[var], Hold[_struct]] := Set[ ...
  • 一个更精确的答案: 如纸和笔将显示: 568784642688024576 / 5 = 113756928537604915.02 该商作为双精度数的最准确的二进制表示是: 0100001101111001010000100101010100101110010000111001001100110011 其中,十进制,是: 1.13756928537604912E17 (注意... 912结束) 现在,如果您将二进制表示减少一个,如下所示: 0100001101111001010000100101010100 ...
  • 它是否会影响编译器或执行时间? 不,它完全一样。 在运行时不会有任何区别,编译时间的差异对于解析{;}来说是微不足道的差异。 如果您因任何原因必须选择一个,请选择一个使您的意图更清晰的人。 Does it make an impact on compiler or execution time? No. It is exactly the same thing. There won't be any difference at run-time, and the difference in compilat ...
  • 显然,逗号的运算符优先级高于“和”但低于&&。 在元素周围加上括号可以: [(a and b), (a or b)] Apparently, the operator precedence for the comma is higher than "and" but lower than &&. Putting parenthesis around the elements works: [(a and b), (a or b)]
  • 假设 : A是标量(使用A符号不是很好) A由上面的常数M-1界定 约束: (1) A <= M * b (2) b <= M * A 检查: A = 2 (1) b = 1 (2) b free A = 0 (1) b free (2) b = 0 b = 1 (1) A free (2) A > 0 b = 0 (1) A = 0 (2) A free 这几乎是: 通常的指标约束方法,如第2页所示 命题演算: x == y <- ...
  • 是的,您可以将OneOrMore嵌入到其他OneOrMore中 - 如果不能,它会严重限制您可以编写的解析器。 我认为如果您做更好的分组,您可以调整现有的解决方案。 在此玩具示例中查看如何定义组: test = """ ...... A B ....... B ....... ...... A B ....... B .......""" from pyparsing import Literal, Word, printables, Group, OneOrMore A = Literal( ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。