本文将带您了解关于os.path.isfile的新内容,同时我们还将为您解释不起作用。为什么?的相关知识,另外,我们还将为您提供关于Cakephp–用Folder::cd()更改目录(绝对的Windo
本文将带您了解关于os.path.isfile的新内容,同时我们还将为您解释不起作用。为什么?的相关知识,另外,我们还将为您提供关于Cakephp – 用Folder :: cd()更改目录(绝对的Windowspath)不起作用、file_get_contents()不起作用、Flush()不起作用、getElementsByName()不起作用?的实用信息。
本文目录一览:- os.path.isfile()不起作用。为什么?(os. path. isfile)
- Cakephp – 用Folder :: cd()更改目录(绝对的Windowspath)不起作用
- file_get_contents()不起作用
- Flush()不起作用
- getElementsByName()不起作用?
os.path.isfile()不起作用。为什么?(os. path. isfile)
我正在尝试这样做:
import os[x for x in os.listdir(''.'') if os.path.isfile(x)][x for x in os.listdir(''dirname'') if os.path.isfile(x)][x for x in os.listdir(os.path.abspath(''dirname'')) if os.path.isfile(os.path.abspath(x))]
第一行有效:
[x for x in os.listdir(''.'') if os.path.isfile(x)]
但是接下来的两个:
[x for x in os.listdir(''dirname'') if os.path.isfile(x)]
和
[x for x in os.listdir(os.path.abspath(''dirname'')) if os.path.isfile(os.path.abspath(x))]
只是输出 []
为什么?
答案1
小编典典因为你需要加入dirname
同x
,os.listdir()
只是列出了内容直接,内容不具有完整路径。
范例-
[x for x in os.listdir(''dirname'') if os.path.isfile(os.path.join(''dirname'',x))]
如果未提供完整路径,则os.path.isfile()
在当前目录中搜索,因此当您给出时''.''
,os.listdir()
将获得正确的列表。
范例-
假设某个文件夹-/a/b/c
具有文件-x
并y
在其中。
当您执行-时os.listdir(''/a/b/c'')
,返回的列表类似于-
[''x'',''y'']
即使您在其中提供绝对路径os.listdir()
,列表中返回的文件也将具有指向目录的相对路径。您将需要手动加入dirx
以获得正确的结果。
在您的第三个示例中,它不起作用,因为它os.path.abspath()
也适用于当前目录,因此,如果执行以下操作-
os.path.abspath(''somefile'')
产生的结果将是–/path/to/current/directory/somefile
不会验证该文件是否为真实文件/目录。
在文档(Emphasis
mine)中明确指出-
os.path.abspath(路径)
返回路径名路径的标准化绝对化版本。在大多数平台上, 这相当于调用函数normpath()如下:
normpath(join(os.getcwd(),path))
。
其中,os.getcwd()
返回当前工作目录的路径。
Cakephp – 用Folder :: cd()更改目录(绝对的Windowspath)不起作用
我不能用cakePHP api中的Folder :: cd()或Folder Constructor方法来设置绝对的Windowspath。 方法调用后没有错误或消息。
例
//path= C:".DS."Users".DS."User.Name".DS."Desktop".DS."Qualitätssicherung".DS."Testmanagement" $fol = new Folder($path); print_r($fol->errors()); // empty echo $fol->path; // empty
我尝试过的其他path定义:
C:UsersUser.NameDesktopQualitätssicherungTestmanagement C:\Users\User.Name\Desktop\Qualitätssicherung\Testmanagement
我应该使用像转义或一个特殊的function来生成一个有效的pathstring?
基于Linux的应用程序中的相同文件夹中的许多图像
batch file/ Powershell – 枚举文件夹中的文件
在Windows上的文件夹select器
在访问文件夹时运行的batch file
如何在打开.bat文件脚本后保持cmd运行
PS:我正在使用cakePHP的最新版本:)
解
在这里find: Stackoverflow
问题是pathvar中的特殊字符。 这段代码处理它:
$string = iconv(mb_detect_encoding($string,"auto"),''Windows-1252'',$string);
哪些字符对于ZIP文件中的文件夹名称无效?
此批处理脚本从不同的目录调用时返回不正确的值
Unrar存档与Debian中的文件夹?
NSIS – 如何将所有文件夹从源代码包含到安装程序
Windows批量基于文件名创build文件夹
IIRC你需要两个反斜杠在Windows驱动器名称后,所以: ''C:\UsersUser.NameDesktopQualitätssicherungTestmanagement''
好的,问题是特殊的问题,我在这里找到了一个适合我的解决方案:
堆栈溢出
$string = iconv(mb_detect_encoding($string,$string);
总结
以上是小编为你收集整理的Cakephp – 用Folder :: cd()更改目录(绝对的Windowspath)不起作用全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
file_get_contents()不起作用
我有一个脚本,它使用file_get_contents()从远程服务器获取json响应。 虽然file_get_contents()在本地文件上正常工作,但不能与http或https一起工作,但它给了我以下错误file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in和file_get_contents(https://api.domain.com/resolve.json?url=blablabla): Failed to open stream: no suitable wrapper Could be found ..这是一个专用的服务器,我有WHM ..我试过
在WHM PHPconfiguration编辑器上设置allow_url_fopen = on ,但是这不起作用。
在发生错误的目录中使用allow_url_fopen = on创build一个PHP.ini文件,但是这不起作用。
添加了ini_set('allow_url_fopen','On'); 到PHP脚本的开始,但这不起作用。
我知道我可以使用curl,但我想知道为什么这不工作..该脚本正常工作在其他服务器和本地主机
更新:
PHPinfo();
给我
在使用Commons IO进行复制时locking文件
是DBus我在找什么?
Apache mod_security阻止国家
在Apache中的任何错误显示500错误
使用SetEnvIf根据SSL_CLIENT_M_SERIAL值更改variables
allow_url_fopen Off allow_url_include Off always_populate_raw_post_data Off
这意味着我的PHP.ini更改没有生效..我做错了什么?
我怎样才能找出httpd.conf文件的位置?
Symfony 3.1.5警告:SessionHandler :: read():会话数据文件不是由你的uid创build的
资源被解释为样式表,但是以MIMEtypestext / html传输
Apache并行path文档根目录
在Apache Axis2 / Rampart中,当生成wsdl和validation策略时,Ws-security Policy 1.2断言<sp:nopassword />没有完全处理?
通过ssh登录到你的服务器并输入
sudo nano /etc/PHP5/apache2/PHP.ini //<<<< ubuntu/debian server,might differ for you
在文件中,只需按"ctrl + w"键入"allow_url_fopen"并返回,最有可能的是你会先解释一下,所以重复搜索几次。 现在你可以改变输入
allow_url_fopen=0
至
allow_url_fopen=1
按"ctrl + x"并用"y"确认文件保存。
然后键入
sudo service apache2 restart
这将重新启动Apache,所以新的PHP.ini配置可以加载。 完成这些步骤后,您应该可以在外部使用file_get_contents 。
边注
如果你找不到你的PHP.ini文件,你可以在你的PHPinfo()的顶部找到加载的PHP.ini文件的路径,
如果您有root权限,请编辑PHP.ini ,通常位于/etc/PHP.ini 。
如果你没有root权限,尝试添加ini_set('allow_url_fopen','On'); 或ini_set('allow_url_fopen','1'); 。
如果您看不到PHP.ini ,请尝试在PHP脚本中使用PHPinfo()来查找PHP.ini位置。
$url= 'https://example.com'; $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false,"verify_peer_name"=>false,),); $response = file_get_contents($url,false,stream_context_create($arrContextOptions));
这将允许你从url中获取内容,不管是HTTPS,也不需要在PHP ini中改变。
Flush()不起作用
请检查这个要点并告诉我,怎么了?
为什么我看不到我的留言?
要点:https :
//gist.github.com/cnaize/895f61b762a9f5ee074c
如果简单,我有两个功能:
func send(param martini.Params, r render.Render) { Ct.Msgs <- param["msg"] fmt.Printf("Sent: %v", param["msg"]) r.JSON(http.StatusOK, Response{"status": "ok"})}
和watch
功能:
func watch(rw http.ResponseWriter, r render.Render) { var msg string ok := true for ok { select { case msg, ok = <-Ct.Msgs: rw.Write([]byte(msg)) fmt.Printf("Wrote: %v", msg) f, ok := rw.(http.Flusher) if ok { f.Flush() fmt.Println("Flushed") } else { r.JSON(http.StatusOK, Response{"status": "error", "descr": "CANT_FLUSH"}) return } } } r.JSON(http.StatusOK, Response{"status": "ok", "descr": "finished"})}
为什么不起作用?
编辑:
我已经更新了要点。现在在哪里:
if i, err := rw.Write([]byte(msg)); err != nil { r.JSON(http.StatusOK, Response{"status": "error", "descr": err.Error()}) return} else { fmt.Printf("i: %v", i)}
我在日志中:
Sent: hello i: 5 Wrote: hello Flushed
但是我什么也没看到。
有任何想法吗?
答案1
小编典典冲洗工作正常。问题是Chrome的纯文本呈现器在显示任何内容之前会等待完整的响应正文。强制将内容类型设置为html以查看增量响应:
func watch(rw http.ResponseWriter, r render.Render) { rw.Header().Set("Content-Type", "text/html") // same code as before}
getElementsByName()不起作用?
我有一个Javascript函数,该函数应使用每次更新该函数时都会增加的数字来更新表单中的隐藏输入字段。
它最初与 getElementById()
一起工作,但是因为我不得不重新设计表单,所以我无法使用php函数为元素分配一个单独的ID,因此我所拥有的只是该元素的唯一名称。
因此,我决定使用Javascript中的 getElementsByName() 修改元素。
这是该元素的HTML
<input type="hidden" value="" name="staff_counter">
这是我的Javascript代码:
window.onload=function()
{
//function is activated by a form button
var staffbox = document.getElementsByName('staff_counter');
staffbox.value = s;
s++;
}
调用函数且输入字段未获得赋值时,Firebug没有错误。
它曾经与getElementById()一起工作,但是为什么突然之间却与getElementsByName()不一起工作呢?
- -我检查了它是文档中唯一的唯一元素。
- -我在激活功能时检查了Firebug的任何错误
这是我从Codeigniter使用的代码来制作元素
// staff_counter is name and the set_value function sets the value from what is
//posted so if the validation fails and the page is reloaded the form element does
// not lose its value
echo form_hidden('staff_counter',set_value('staff_counter'));
谢谢
我们今天的关于os.path.isfile和不起作用。为什么?的分享已经告一段落,感谢您的关注,如果您想了解更多关于Cakephp – 用Folder :: cd()更改目录(绝对的Windowspath)不起作用、file_get_contents()不起作用、Flush()不起作用、getElementsByName()不起作用?的相关信息,请在本站查询。
本文标签: