首页 \ 问答 \ 我应该从PHP中删除表单中的临时文件发送(Should I remove temporary file send from form in PHP)

我应该从PHP中删除表单中的临时文件发送(Should I remove temporary file send from form in PHP)

我正在玩各种ajax上传者。 在分析他们的服务器端代码时,我看到这样的事情:

@unlink($_FILES['file']['tmp_name'])

它要么静音(如上所述),所以什么也不做(在我的情况下)或取消静音,所以抛出警告,禁止访问临时文件夹(在我的情况下)并中断脚本的执行。

我错过了什么? 我总是被告知,我们不应该触摸通过PHP表单传输的临时文件 。 因为这是不必要的(并禁止某些时间,就像我的情况一样)。 当脚本结束时,PHP将执行所有清理 - 即删除所有上传的临时文件。

上面的代码是什么原因? 是否适用于这种情况,当脚本中断时,PHP会因某些严重错误而停止,因此无法删除临时文件? 还是有另一个原因?

编辑 :很遗憾,即使在Plupload示例代码中我也发现了这种错误。


I'm playing with various ajax uploaders. When analyzing their server-side code, I see something like this:

@unlink($_FILES['file']['tmp_name'])

It is either muted one (like above), so does nothing (in my case) or unmuted one, so throws a warning, that access to temporary folder is prohibited (in my case) and breaks execution of a script.

What am I missing? I was always told, that we should not touch temporary files transmited via PHP form. Because this is unnecessary (and somethimes prohibited, like in my case). PHP will do all the cleaning, when script ends -- i.e. remove all uploaded temporary files.

What is the reason in code like above? Is it for the case, when script breaks, PHP is halted with some critical error and thus isn't able to remove temporary files? Or there is another reason?

Edit: It is quite pity, that I found this kind of mistake even in Plupload example code.


原文:
更新时间:2022-03-18 16:03

最满意答案

这是一种方法(我假设有一个拼写错误,你想要的是x3 * (mynet(x2) - mynet(x1)) ?):

import tensorflow as tf
import numpy as np

class MLP:
    def __init__(self, x1, x2, sizes, activations):
        x_sizes = [tf.shape(x1)[0], tf.shape(x2)[0]]
        last_out = tf.concat([x1, x2], axis=0)
        self.layers = []
        for l, size in enumerate(sizes[1:]):
            self.layers.append(last_out)
            last_out = tf.layers.dense(last_out, size, activation=activations[l], kernel_initializer=tf.glorot_uniform_initializer())
        self.layers.append(last_out)
        self.x1_eval, self.x2_eval = tf.split(last_out, x_sizes, axis=0)



def main():
    session = tf.Session()

    dim = 3
    nn_sizes = [dim, 15, 1]
    nn_activations = [tf.nn.tanh, tf.nn.tanh, tf.identity]

    w = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='mynet')
    x1 = tf.placeholder(dtype=tf.float32, shape=[None, dim], name='x1')
    x2 = tf.placeholder(dtype=tf.float32, shape=[None, dim], name='x2')
    x3 = tf.placeholder(dtype=tf.float32, shape=[None, 1], name='x3')

    mynet = MLP(x1, x2, nn_sizes, nn_activations)

    myfun = tf.reduce_sum(tf.multiply(x3, (mynet.x2_eval - mynet.x1_eval)))

    optimizer = tf.contrib.opt.ScipyOptimizerInterface(myfun,var_list=w)

    n = 1000
    x1_samples = np.asmatrix(np.random.rand(n,dim))
    x2_samples = np.asmatrix(np.random.rand(n,dim))
    x3_samples = np.asmatrix(np.random.rand(n,1))

    session.run(tf.global_variables_initializer())
    print(session.run(myfun, {x1: x1_samples, x2: x2_samples, x3: x3_samples}))
    optimizer.minimize(session, {x1: x1_samples, x2: x2_samples, x3: x3_samples})
    print(session.run(myfun, {x1: x1_samples, x2: x2_samples, x3: x3_samples}))


if __name__ == '__main__':
    main()

Here's one approach (I assume there is a typo and what you want is x3 * (mynet(x2) - mynet(x1))?):

import tensorflow as tf
import numpy as np

class MLP:
    def __init__(self, x1, x2, sizes, activations):
        x_sizes = [tf.shape(x1)[0], tf.shape(x2)[0]]
        last_out = tf.concat([x1, x2], axis=0)
        self.layers = []
        for l, size in enumerate(sizes[1:]):
            self.layers.append(last_out)
            last_out = tf.layers.dense(last_out, size, activation=activations[l], kernel_initializer=tf.glorot_uniform_initializer())
        self.layers.append(last_out)
        self.x1_eval, self.x2_eval = tf.split(last_out, x_sizes, axis=0)



def main():
    session = tf.Session()

    dim = 3
    nn_sizes = [dim, 15, 1]
    nn_activations = [tf.nn.tanh, tf.nn.tanh, tf.identity]

    w = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='mynet')
    x1 = tf.placeholder(dtype=tf.float32, shape=[None, dim], name='x1')
    x2 = tf.placeholder(dtype=tf.float32, shape=[None, dim], name='x2')
    x3 = tf.placeholder(dtype=tf.float32, shape=[None, 1], name='x3')

    mynet = MLP(x1, x2, nn_sizes, nn_activations)

    myfun = tf.reduce_sum(tf.multiply(x3, (mynet.x2_eval - mynet.x1_eval)))

    optimizer = tf.contrib.opt.ScipyOptimizerInterface(myfun,var_list=w)

    n = 1000
    x1_samples = np.asmatrix(np.random.rand(n,dim))
    x2_samples = np.asmatrix(np.random.rand(n,dim))
    x3_samples = np.asmatrix(np.random.rand(n,1))

    session.run(tf.global_variables_initializer())
    print(session.run(myfun, {x1: x1_samples, x2: x2_samples, x3: x3_samples}))
    optimizer.minimize(session, {x1: x1_samples, x2: x2_samples, x3: x3_samples})
    print(session.run(myfun, {x1: x1_samples, x2: x2_samples, x3: x3_samples}))


if __name__ == '__main__':
    main()

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。