本文整理汇总了PHP中stream_copy_to_stream函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_copy_to_stream函数的具体用法?PHP stream_copy_to_stream怎么用?PHP stream_copy_to_stream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_copy_to_stream函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
function show()
{
$folder = 'tmp/';
if (isset($_REQUEST['qqfile'])) {
$file = $_REQUEST['qqfile'];
$path = $folder . $file;
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $_SERVER["CONTENT_LENGTH"]) {
die("{'error':'size error'}");
}
if (is_writable($folder)) {
$target = fopen($path, 'w');
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
echo "{success:true, target:'{$file}'}";
} else {
die("{'error':'not writable: {$path}'}");
}
} else {
$file = $_FILES['qqfile']['name'];
$path = $folder . $file;
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
die("{'error':'permission denied'}");
}
echo "{success:true, target:'{$file}'}";
}
}
示例2: _report
/**
* Reports a single spam message.
*
* @param string $message Message content.
*
* @return boolean False on error, true on success.
*/
protected function _report($message)
{
/* Use a pipe to write the message contents. This should be secure. */
$proc = proc_open($this->_binary, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
if (!is_resource($proc)) {
$this->_logger->err(sprintf('Cannot open spam reporting program: %s', $proc));
return false;
}
if (is_resource($message)) {
rewind($message);
stream_copy_to_stream($message, $pipes[0]);
} else {
fwrite($pipes[0], $message);
}
fclose($pipes[0]);
$stderr = '';
while (!feof($pipes[2])) {
$stderr .= fgets($pipes[2]);
}
fclose($pipes[2]);
proc_close($proc);
if (!empty($stderr)) {
$this->_logger->err(sprintf('Error reporting spam: %s', $stderr));
return false;
}
return true;
}
示例3: copy
/**
* Copies a file or directory.
* @return void
* @throws Nette\IOException
*/
public static function copy($source, $dest, $overwrite = TRUE)
{
if (stream_is_local($source) && !file_exists($source)) {
throw new Nette\IOException("File or directory '{$source}' not found.");
} elseif (!$overwrite && file_exists($dest)) {
throw new Nette\InvalidStateException("File or directory '{$dest}' already exists.");
} elseif (is_dir($source)) {
static::createDir($dest);
foreach (new \FilesystemIterator($dest) as $item) {
static::delete($item);
}
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir()) {
static::createDir($dest . '/' . $iterator->getSubPathName());
} else {
static::copy($item, $dest . '/' . $iterator->getSubPathName());
}
}
} else {
static::createDir(dirname($dest));
if (@stream_copy_to_stream(fopen($source, 'r'), fopen($dest, 'w')) === FALSE) {
// @ is escalated to exception
throw new Nette\IOException("Unable to copy file '{$source}' to '{$dest}'.");
}
}
}
示例4: extendfile
function extendfile($path, $len, $maxlen)
{
$currlen = 0;
if (file_exists($path)) {
$currlen = filesize($path);
}
if ($currlen < $maxlen) {
$err = createdirs($path, 0);
if ($err != 0) {
return $err;
}
$zero = fopen('/dev/zero', 'r');
if (!$zero) {
return 2;
}
$dest = fopen($path, 'a');
if (!$dest) {
return 2;
}
stream_copy_to_stream($zero, $dest, min($len, $maxlen - $currlen));
fclose($zero);
fclose($dest);
}
return 0;
}
示例5: handleUpload
public static function handleUpload()
{
echo "0\n";
//register_shutdown_function(array('cc_Ajax_Upload', 'shutdown'));
echo "1\n";
$headers = getallheaders();
if (!(isset($headers['Content-Type'], $headers['Content-Length'], $headers['X-File-Size'], $headers['X-File-Name']) && $headers['Content-Length'] === $headers['X-File-Size'])) {
exit('Error');
}
echo "A\n";
$maxSize = 80 * 1024 * 1024;
if (false === (self::$tmpfile = tempnam('tmp', 'upload_'))) {
exit(json_encode(array('status' => 'error', 'filename' => 'temp file not possible')));
}
echo "A\n";
$fho = fopen(self::$tmpfile, 'w');
$fhi = fopen('php://input', 'r');
$tooBig = $maxSize <= stream_copy_to_stream($fhi, $fho, $maxSize);
echo "A\n";
if ($tooBig) {
exit(json_encode(array('status' => 'error', 'filename' => 'upload too big')));
}
echo "A\n";
exit(json_encode(array('status' => 'success', 'filename' => $headers['X-File-Name'])));
}
示例6: combineChunks
public function combineChunks($uploadDirectory)
{
$uuid = $_POST['qquuid'];
$name = $this->getName();
$targetFolder = $this->chunksFolder . DIRECTORY_SEPARATOR . $uuid;
$totalParts = isset($_REQUEST['qqtotalparts']) ? (int) $_REQUEST['qqtotalparts'] : 1;
$target = join(DIRECTORY_SEPARATOR, array($uploadDirectory, $uuid, $name));
$this->uploadName = $name;
if (!file_exists($target)) {
mkdir(dirname($target));
}
$target = fopen($target, 'wb');
for ($i = 0; $i < $totalParts; $i++) {
$chunk = fopen($targetFolder . DIRECTORY_SEPARATOR . $i, "rb");
stream_copy_to_stream($chunk, $target);
fclose($chunk);
}
// Success
fclose($target);
for ($i = 0; $i < $totalParts; $i++) {
unlink($targetFolder . DIRECTORY_SEPARATOR . $i);
}
rmdir($targetFolder);
return array("success" => true, "uuid" => $uuid);
}
示例7: copyContentsToFile
/**
* @param string $path
*/
public function copyContentsToFile($path)
{
$fp = fopen($path, 'w');
$this->seek(0);
stream_copy_to_stream($this->phpStream, $fp);
fclose($fp);
}
示例8: save
function save($path)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $this->getSize()) {
return false;
}
/////////////////////////////////////////////////////
$target = fopen(JPATH_SITE . "/tmp/" . basename($path), "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
$extension = explode(".", $path);
$extension_file = $extension[count($extension) - 1];
if ($extension_file == 'jpg' || $extension_file == 'jpeg' || $extension_file == 'png' || $extension_file == 'gif' || $extension_file == 'JPG' || $extension_file == 'JPEG' || $extension_file == 'PNG' || $extension_file == 'GIF') {
$image_size = getimagesize(JPATH_SITE . "/tmp/" . basename($path));
}
if (isset($image_size) && $image_size === FALSE) {
unlink(JPATH_SITE . "/tmp/" . basename($path));
return false;
}
unlink(JPATH_SITE . "/tmp/" . basename($path));
/////////////////////////////////////////////////////
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
示例9: copy
/**
* Copies and transforms a file.
*
* This method only copies the file if the origin file is newer than the target file.
*
* By default, if the target already exists, it is not overridden.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param boolean $override Whether to override an existing file or not
*
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new IOException(sprintf('Failed to copy %s because file does not exist', $originFile));
}
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
}
if (!$doCopy) {
return;
}
$event = new FileCopyEvent($originFile, $targetFile);
$event = $this->event_dispatcher->dispatch(FilesystemEvents::COPY, $event);
$originFile = $event->getSource();
$targetFile = $event->getTarget();
if ($event->isModified()) {
file_put_contents($targetFile, $event->getContent());
return;
}
// No listeners modified the file, so just copy it (original behaviour & code)
// https://bugs.php.net/bug.php?id=64634
$source = fopen($originFile, 'r');
$target = fopen($targetFile, 'w+');
stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile));
}
}
示例10: localhost
function localhost($r, $w)
{
echo "<p>Read <b>{$r}</b>, Write <b>{$w}</b>\n";
$fr = @fopen("http://www.google.com/", $r);
if ($fr === false) {
die('NO NETWORK CONNECTION!');
}
$fw = fopen("stream_copy_to_stream_{$r}_{$w}.txt", $w);
echo "\n\nCOPIED: <b>" . stream_copy_to_stream($fr, $fw) . "</b>\n";
fclose($fr);
fclose($fw);
/*
$f = fopen("stream_copy_to_stream_${r}_${w}.txt", "rb");
while (false !== ($c = fgetc($f)))
{
$c = (string)$c;
//echo ord($c);
if ($c == "\n") echo "[\\n]\n";
else if ($c == "\r") echo "[\\r]\r";
else if ($c == "<") echo "<";
else if ($c == ">") echo ">";
else echo $c;
}
fclose($f);
*/
unlink("stream_copy_to_stream_{$r}_{$w}.txt");
}
示例11: conf__formulario
function conf__formulario(toba_ei_formulario $form)
{
if ($this->s__mostrar == 1) {
// si presiono el boton alta entonces muestra el formulario para dar de alta un nuevo registro
$this->dep('formulario')->descolapsar();
$form->ef('nro_norma')->set_obligatorio('true');
$form->ef('tipo_norma')->set_obligatorio('true');
$form->ef('emite_norma')->set_obligatorio('true');
$form->ef('fecha')->set_obligatorio('true');
} else {
$this->dep('formulario')->colapsar();
}
if ($this->dep('datos')->esta_cargada()) {
$datos = $this->dep('datos')->tabla('norma')->get();
$fp_imagen = $this->dep('datos')->tabla('norma')->get_blob('pdf');
if (isset($fp_imagen)) {
$temp_nombre = md5(uniqid(time())) . '.pdf';
$temp_archivo = toba::proyecto()->get_www_temp($temp_nombre);
$temp_fp = fopen($temp_archivo['path'], 'w');
stream_copy_to_stream($fp_imagen, $temp_fp);
fclose($temp_fp);
$tamano = round(filesize($temp_archivo['path']) / 1024);
$datos['imagen_vista_previa'] = "<a target='_blank' href='{$temp_archivo['url']}' >norma</a>";
$datos['pdf'] = 'tamano: ' . $tamano . ' KB';
} else {
$datos['pdf'] = null;
}
return $datos;
}
}
示例12: copy
/**
* Copies a file.
*
* This method only copies the file if the origin file is newer than the target file.
*
* By default, if the target already exists, it is not overridden.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param bool $override Whether to override an existing file or not
*
* @throws FileNotFoundException When originFile doesn't exist
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile) && null === parse_url($originFile, PHP_URL_HOST)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
}
if ($doCopy) {
// https://bugs.php.net/bug.php?id=64634
if (false === ($source = @fopen($originFile, 'r'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
}
if (false === ($target = @fopen($targetFile, 'w'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
}
stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
}
}
示例13: ajaxProcess
protected function ajaxProcess()
{
$upload_path = $this->_getUploadPath();
$newFilename = $this->_getNewFilename();
$newFile = $upload_path . DIRECTORY_SEPARATOR . $newFilename;
$input = fopen("php://input", "r");
$temp_path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . "tmp";
if (!is_writable($temp_path)) {
mkdir("{$temp_path}", 0777);
}
$tempFilename = tempnam($temp_path, 'temp_');
$tempfile = fopen($tempFilename, 'w');
$filesize = stream_copy_to_stream($input, $tempfile);
fclose($tempfile);
fclose($input);
$filename = $this->options['file'];
$file = array('name' => "{$filename}", 'tmp_name' => "{$tempFilename}");
ApuImageCropper::getInstance()->crop($file, $newFilename, $this->options['context']);
if (rename($tempFilename, $newFile)) {
$this->uploadedFilename = $newFilename;
$this->uploadedFilesize = $filesize;
$this->_setOptions();
$this->save();
} else {
$this->response = '{ "error" => "An error has occurred while trying to upload your image!", "e_id" : "' . $e_id . '" }';
}
}
示例14: save
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
if (!$temp) {
$temp = fopen("php://temp", "wb");
}
if (!$input || !$temp) {
if ($input) {
fclose($input);
}
return false;
}
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $this->getSize()) {
return false;
}
$target = fopen($path, "w");
if (!$target) {
return false;
}
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
示例15: writeStream
/**
* Write a new file using a stream.
*
* @param string $path
* @param resource $resource
* @param Config $config
* @return array|false
*/
public function writeStream($path, $resource, Config $config)
{
$fullPath = $this->applyPathPrefix($path);
$stream = $this->share->write($fullPath);
stream_copy_to_stream($resource, $stream);
return fclose($stream) ? compact('path') : false;
}