发布到动态创建的文件
我们的网站会即时创建文件,向网络上的世界呈现用户指定的数据。
每个这样的“_present.php”文件中都有一个需要发送给自身的表单——唯一的问题是,该文件是根据上传的用户数据动态创建的,并且文件名也有些任意。
这是过程
1) a 'standard' file called _present.php has a common form "TheForm" in it
2) this file, _present.php, is copied to Yf9iZ17a.php (for example) when
the user uploads data -- and from that point, Yf9iZ17a.php presents
that user's just-uploaded data
3) and "TheForm" is inside this Yf9iZ17a.php, which again is just a copy of
_present.php, but modified to handle the user's just-uploaded data
非常简单。 _present.php 里面有“TheForm”;用户上传他们的数据;我们将 _present.php 复制到 该用户数据的文件名。
问题是——我们需要 TheForm 来发布到它自己的 文件名,动态创建的。
换句话说,这还不够:
<form name="TheForm" method="post" action="_present.php">
但是,这可以工作:
<form name="TheForm" method="post" action="Yf9iZ17a.php">
但是我们不能用“Yf9iZ17a.php”对表单的 html 进行硬编码,因为 - 该文件名是创建的 动态地、即时地、在运行时。
这是我们成功执行的一个失败:
<form name="TheForm" method="post" action="<?php echo __FILE__ ; ?>">
“查看页面源代码”足以证明“php echo FILE”正确地回显了 Yf9iZ17a.php 的完整路径(不是相对路径,完整路径)。
好吧,那是行不通的。为浏览器提供文件的完全限定路径名—— 服务器上的文件——那么为什么你首先要这样做,除非 你正在抓住救命稻草。所以那是一次失败。
当然会出现这种情况,动态创建的文件名,其内部表单必须发布到这些文件名 - 解决这个问题的最好方法是什么?
Our site creates files on-the-fly that present user-specified data to the world on the web.
There is in each such '_present.php' file a form that needs to post to itself -- only problem is, the file is created dynamically based on uploaded user data and the filename is also somewhat arbitrary.
Here's the process
1) a 'standard' file called _present.php has a common form "TheForm" in it
2) this file, _present.php, is copied to Yf9iZ17a.php (for example) when
the user uploads data -- and from that point, Yf9iZ17a.php presents
that user's just-uploaded data
3) and "TheForm" is inside this Yf9iZ17a.php, which again is just a copy of
_present.php, but modified to handle the user's just-uploaded data
Pretty simple. _present.php has "TheForm" inside it; the user uploads their data; we copy _present.php to a
filename for that user's data.
The PROBLEM is -- we need TheForm to post to its own
filename, which is dynamically created.
In other words, this won't suffice:
<form name="TheForm" method="post" action="_present.php">
However, this WOULD work:
<form name="TheForm" method="post" action="Yf9iZ17a.php">
But we cannot hard-code the form's html with "Yf9iZ17a.php" because -- that filename is created
dynamically, on-the-fly, at runtime.
This is one failure we have succeeded in executing:
<form name="TheForm" method="post" action="<?php echo __FILE__ ; ?>">
A 'View Page Source' sure enough proves that "php echo FILE" correctly echos the
full path (not relative path, the full path) to Yf9iZ17a.php.
Well that won't work. Giving the browser the fully-qualified pathname to a file --
a file that is on the server -- well why would you WANT to do it in the first place unless
you're grasping at straws. So that was a failure.
Surely this comes up, dynamically created filenames whose internal forms must post to those filenames --
what's the best way to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以用这个来代替?
You can use this instead, perhaps?