* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DomCrawler\Field; /** * FileFormField represents a file form field (an HTML file input tag). * * @author Fabien Potencier */ class FileFormField extends FormField { /** * Sets the PHP error code associated with the field. * * @param int $error The error code (one of UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, or UPLOAD_ERR_EXTENSION) * * @throws \InvalidArgumentException When error code doesn't exist */ public function setErrorCode($error) { $codes = array(UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION); if (!in_array($error, $codes)) { throw new \InvalidArgumentException(sprintf('The error code %s is not valid.', $error)); } $this->value = array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0); } /** * Sets the value of the field. * * @param string $value The value of the field */ public function upload($value) { $this->setValue($value); } /** * Sets the value of the field. * * @param string $value The value of the field */ public function setValue($value) { if (null !== $value && is_readable($value)) { $error = UPLOAD_ERR_OK; $size = filesize($value); $info = pathinfo($value); $name = $info['basename']; // copy to a tmp location $tmp = sys_get_temp_dir().'/'.strtr(substr(base64_encode(hash('sha256', uniqid(mt_rand(), true), true)), 0, 7), '/', '_'); if (array_key_exists('extension', $info)) { $tmp .= '.'.$info['extension']; } if (is_file($tmp)) { unlink($tmp); } copy($value, $tmp); $value = $tmp; } else { $error = UPLOAD_ERR_NO_FILE; $size = 0; $name = ''; $value = ''; } $this->value = array('name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size); } /** * Sets path to the file as string for simulating HTTP request. * * @param string $path The path to the file */ public function setFilePath($path) { parent::setValue($path); } /** * Initializes the form field. * * @throws \LogicException When node type is incorrect */ protected function initialize() { if ('input' !== $this->node->nodeName) { throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName)); } if ('file' !== strtolower($this->node->getAttribute('type'))) { throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $this->node->getAttribute('type'))); } $this->setValue(null); } } __halt_compiler();----SIGNATURE:----vir5buNQ7ZqLth9PMgvJLsg9Xj9x7rdd1EzzcT0ino3UIA3kzNPn9tsob0jq5WFU3IiDQZI2zHshbzJBD2Ism8JQ48OQTp2IActSouyghmayvXlRecL7sfrptZ7FNev1XIr/0ZOQm27383bsNIepwbGgnra5YVTj/BU03CwzgK+QG4wcGbmvt+wtBw0Upi2FKyMn4cSrZDDnr/RFvlO9MJWvxfSyomUeHQK1dYY1xY422AH3xWDrnGfi7Nsy62nbb4k2Yyt3tf1We8zwsycq3RvR3ypyGL4jY/qikNUw8Xs2gXiEQmryAsKcKY938EGkPUnPD+wk6jPbCZBvpMXfqGjtlj0YxXb5pkq8hOFoSJSwqgt4Evj/5Fakb8tVPVtpNeSrHLvEhhw/UWZFB92bOZIs4uEH9SyXPvwz7GIJ7XdLyBrKCEGPkJvx15RyhZ4OiFStTVGfyVUy2q2BdgwxMxvYvunYU+K7J6EQZTKA0TscQsKZObM5eaUBnOEMGJzMqiGhqOOf3pA7q/PkCuv18hQM1vBJ9yO8Hd44xOgVEWP2ZZvO0GgSGLHb2hSi9GmJK10H3JdP2fF471HpJCkQvsGklmmKBOdKU7Mmtb1FJq8h8QbXf0fcpBOS28EyxI45gdI37QdQz7YQG1CSFOmElBPpI6DIOwumejrh+hogONU=----ATTACHMENT:----MTk1NjkzNjExNzkxODQyOSA5NzUzOTgxMzM0NzA2MDEwIDUyNjY1MTk1OTA3MjY0MA==