Copy php ошибка

I’m getting error while using php function copy()

Warning: copy() [function.copy]:
Couldn’t resolve host name in

Warning:
copy(http://www.foodtest.ru/images/big_img/sausage_3.jpg)
[function.copy]: failed to open
stream: operation failed in

what’s wrong with that url?

asked Mar 3, 2011 at 0:33

Tuco's user avatar

4

Try enclosing the url withing quotes «».

answered Mar 3, 2011 at 0:36

Raja's user avatar

RajaRaja

4425 silver badges17 bronze badges

2

Try plugging in a destination argument and make sure to have the soft ticks around the arguments.

copy("http://www.foodtest.ru/images/big_img/sausage_3.jpg", "./file.jpg");

answered Mar 3, 2011 at 0:37

a.stgeorge's user avatar

a.stgeorgea.stgeorge

3041 silver badge7 bronze badges

8

a little old, but important to pay attention, in case this helps someone who gets here:

copy command is folder-case sensitive, so if you try to copy 1.jpg from a folder called «ThumbImages» like that:

copy("thumbimages/1.jpg","[destination...]")

it will not find the folder.

notice you are using upper or lower case that matches the folder name

  • I just reached this post while trying to figure out an issue and now that it is solved, I hope it will help others.

answered Jun 14, 2017 at 15:43

marble's user avatar

(PHP 4, PHP 5, PHP 7, PHP 8)

copyКопирует файл

Описание

copy(string $from, string $to, ?resource $context = null): bool

Если вы хотите переименовать файл, используйте функцию rename().

Список параметров

from

Путь к исходному файлу.

to

Путь к целевому файлу. Если to является URL,
то операция копирования может завершиться ошибкой, если обёртка
URL не поддерживает перезаписывание существующих файлов.

Внимание

Если целевой файл уже существует, то он будет перезаписан.

context

Корректный ресурс контекста, созданный функцией
stream_context_create().

Возвращаемые значения

Возвращает true в случае успешного выполнения или false в случае возникновения ошибки.

Примеры

Пример #1 Пример использования функции copy()

<?php
$file
= 'example.txt';
$newfile = 'example.txt.bak';

if (!

copy($file, $newfile)) {
echo
"не удалось скопировать $file...\n";
}
?>

Смотрите также

  • move_uploaded_file() — Перемещает загруженный файл в новое место
  • rename() — Переименовывает файл или директорию
  • Раздел руководства «Загрузка файлов»

simonr_at_orangutan_dot_co_dot_uk

19 years ago

Having spent hours tacking down a copy() error: Permission denied , (and duly worrying about chmod on winXP) , its worth pointing out that the 'destination' needs to contain the actual file name ! --- NOT just the path to the folder you wish to copy into.......
DOH !
hope this saves somebody hours of fruitless debugging

cooper at asu dot ntu-kpi dot kiev dot ua

17 years ago

It take me a long time to find out what the problem is when i've got an error on copy(). It DOESN'T create any directories. It only copies to existing path. So create directories before. Hope i'll help,

someone at terrasim dot com

1 year ago

On Windows, php-7.4.19-Win32-vc15-x64 - copy() corrupted a 6GB zip file. Our only recourse was to write:

function file_win_copy( $src, $dst ) {
shell_exec( 'COPY "'.$src.'" "'.$dst.'"');
return file_exists($dest);
}

steve a h

15 years ago

Don't forget; you can use copy on remote files, rather than doing messy fopen stuff. e.g.

<?php
if(!@copy('http://someserver.com/somefile.zip','./somefile.zip'))
{
$errors= error_get_last();
echo
"COPY ERROR: ".$errors['type'];
echo
"<br />\n".$errors['message'];
} else {
echo
"File copied from remote!";
}
?>

promaty at gmail dot com

12 years ago

Here is a simple script that I use for removing and copying non-empty directories. Very useful when you are not sure what is the type of a file.

I am using these for managing folders and zip archives for my website plugins.

<?php// removes files and non-empty directories
function rrmdir($dir) {
if (
is_dir($dir)) {
$files = scandir($dir);
foreach (
$files as $file)
if (
$file != "." && $file != "..") rrmdir("$dir/$file");
rmdir($dir);
}
else if (
file_exists($dir)) unlink($dir);
}
// copies files and non-empty directories
function rcopy($src, $dst) {
if (
file_exists($dst)) rrmdir($dst);
if (
is_dir($src)) {
mkdir($dst);
$files = scandir($src);
foreach (
$files as $file)
if (
$file != "." && $file != "..") rcopy("$src/$file", "$dst/$file");
}
else if (
file_exists($src)) copy($src, $dst);
}
?>

Cheers!

absorbentshoulderman at gmail dot com

10 years ago

A nice simple trick if you need to make sure the folder exists first:

<?php

$srcfile

='C:\File\Whatever\Path\Joe.txt';
$dstfile='G:\Shared\Reports\Joe.txt';
mkdir(dirname($dstfile), 0777, true);
copy($srcfile, $dstfile);?>

That simple.

ASchmidt at Anamera dot net

9 years ago

Below a code snippet for downloading a file from a web server to a local file.

It demonstrates useful customizations of the request (such as setting a User-Agent and Referrer, often required by web sites), and how to download only files if the copy on the web site is newer than the local copy.

It further demonstrates the processing of response headers (if set by server) to determine the timestamp and file name. The file type is checked because some servers return a 200 OK return code with a textual "not found" page, instead of a proper 404 return code.

<?php
// $fURI: URL to a file located on a web server
// $target_file: Path to a local file
if ( file_exists( $target_file ) ) {
$ifmodhdr = 'If-Modified-Since: '.date( "r", filemtime( $target_file ) )."\r\n";
}
else {
$ifmodhdr = '';
}
// set request header for GET with referrer for modified files, that follows redirects
$arrRequestHeaders = array(
'http'=>array(
'method' =>'GET',
'protocol_version' =>1.1,
'follow_location' =>1,
'header'=> "User-Agent: Anamera-Feed/1.0\r\n" .
"Referer: $source\r\n" .
$ifmodhdr
)
);
$rc = copy( $fURI, $target_file, stream_context_create($arrRequestHeaders) );// HTTP request completed, preserve system error, if any
if( $rc ) {
if (
fclose( $rc ) ) {
unset(
$err );
}
else {
$err = error_get_last();
}
}
else {
$err = error_get_last();
}
// Parse HTTP Response Headers for HTTP Status, as well filename, type, date information
// Need to start from rear, to get last set of headers after possible sets of redirection headers
if ( $http_response_header ) {
for (
$i = sizeof($http_response_header) - 1; $i >= 0; $i-- ) {
if (
preg_match('@^http/\S+ (\S{3,}) (.+)$@i', $http_response_header[$i], $http_status) > 0 ) {
// HTTP Status header means we have reached beginning of response headers for last request
break;
}
elseif (
preg_match('@^(\S+):\s*(.+)\s*$@', $http_response_header[$i], $arrHeader) > 0 ) {
switch (
$arrHeader[1] ) {
case
'Last-Modified':
if ( !isset(
$http_content_modtime) ) {
$http_content_modtime = strtotime( $arrHeader[2] );
}
break;
case
'Content-Type':
if ( !isset(
$http_content_image_type) ) {
if (
preg_match('@^image/(\w+)@ims', $arrHeader[2], $arrTokens) > 0 ) {
if (
in_array(strtolower($arrTokens[1]), $arrValidTypes)) {
$http_content_image_type = $arrTokens[1];
break;
}
}
throw new
Exception( "Error accessing file $fURI; invalid content type: $arrHeader[2]", 2);
}
break;
case
'Content-Disposition':
if ( !isset(
$http_content_filename) && preg_match('@filename\\s*=\\s*(?|"([^"]+)"|([\\S]+));?@ims', $arrHeader[2], $arrTokens) > 0 ) {
$http_content_filename = basename($arrTokens[1]);
}
break;
}
}
}
}

if (

$http_status ) {
// Make sure we have good HTTP Status
switch ( $http_status[1] ) {
case
'200':
// SUCCESS: HTTP Status is "200 OK"
break;
case
'304':
throw new
Exception( "Remote file not newer: $fURI", $http_status[1] );
break;
case
'404':
throw new
Exception( "Remote file not found: $fURI", $http_status[1] );
break;
default:
throw new
Exception( "HTTP Error, $http_status[2], accessing $fURI", $http_status[1] );
break;
}
}
elseif (
$err ) {
// Protocol / Communication error
throw new Exception( $err['message']/*."; Remote file: $fURI"*/, $err['type'] );
}
else {
// No HTTP status and no error
throw new customException( "Unknown HTTP response accessing $fURI: $http_response_header[0]", -1 );
}
?>

Notes:
1. Currently copy() does NOT appropriately handle the 304 response code. Instead of NOT performing a copy (possibly setting the RC), it will overwrite the target file with an zero length file.
2. There may be a problem accessing a list of remote files when HTTP 1.1 protocol is used. If you experience time-out errors, try the default 1.0 protocol version.

hugo_2000 at gmx dot at

8 years ago

If you try to copy a file to itself - e.g. if the target directory is just a symlink to the source directory - copy will return false. just like on the command line.

Vinicio Coletti

7 years ago

Copying large files under Windows 8.1, from one NTFS filesystem to another NTFS filesystem, results in only the first 4 GiB copied and the rest of the file is ignored.

So, if you think to have files larger than 4 GiB, instead of doing:
copy($source,$destination);
it is much better to do something like:
exec("xcopy $source $destination");

I will check to see if this issue is valid also under Linux.
It depends on PHP not being compiled in 64 bit mode?

tom at r dot je

15 years ago

It's worth noting that copy() sets the destination file's last modified time/date.

gimmicklessgpt at gmail dot com

14 years ago

Here's a simple recursive function to copy entire directories

Note to do your own check to make sure the directory exists that you first call it on.

<?php

function recurse_copy($src,$dst) {

$dir = opendir($src);

@
mkdir($dst);

while(
false !== ( $file = readdir($dir)) ) {

if ((
$file != '.' ) && ( $file != '..' )) {

if (
is_dir($src . '/' . $file) ) {

recurse_copy($src . '/' . $file,$dst . '/' . $file);

}

else {

copy($src . '/' . $file,$dst . '/' . $file);

}

}

}

closedir($dir);

}

?>

eng-ayman at aymax dot net

14 years ago

some hosts disable copy() function and say its for security

and for some copy is important so this is and simple function that do same as copy function effect

how smart php can help us l like php

<?php

function copyemz($file1,$file2){

$contentx =@file_get_contents($file1);

$openedfile = fopen($file2, "w");

fwrite($openedfile, $contentx);

fclose($openedfile);

if (
$contentx === FALSE) {

$status=false;

}else
$status=true;

return

$status;

}

?>

Bas Vijfwinkel

8 years ago

Paths and filenames with Japanese characters are not handled correctly if you are running Apache/PHP on a Windows machine.
With the following code you can convert e.g. the network path to the appropriate encoding so that Windows understands where to look:

<?PHPfunction convertPath($path)
{
//split networkpath into parts
$parts = explode('\\',$path);
// convert each part to SJIS
foreach($parts as $index => $part)
{
$parts[$index] = iconv('UTF-8','SJIS//IGNORE',$part);
}
// put the network path back together
return implode('\\',$parts);
}
$oldname = convertPath('c:/Temp/ほげほげ.pdf');
$newname = convertPath('\\\\PFSV0100\\DATA\\06:個人別\\333328_ほげほげ\\test_あいうえお.pdf');copy($oldname, $newname);
?>

There are however a number of characters that cannot be converted correctly like '②' and '﨑' because there are no SJIS equivalents.

jim dot mcgowen at cox dot net

15 years ago

On Windows (not sure about Linux) copy will overwrite an existing file but will not change the case of the existing filename.

In other words if I have a file named "Myfile.txt" and I overwrite it using copy with a file named "MyFile.txt" it will overwrite it but the filename will remain "Myfile.txt".

If this is a problem (as it was for me) use unlink to delete the existing file first.

kadnan at yahoo dot com

19 years ago

you can also try xcopy command by using Shell to move/copy files/folders from one place to another

here is the code:

<?php

exec
('xcopy c:\\myfolder d:\\myfolder /e/i', $a, $a1);

?>



by executing this command, it will move folder along with all contents to destination.

-adnan

Sina Salek

14 years ago

Thanks for all the comments, i wrote this function for fully supporting file and directory copy.

As you may have noticed there are feature that didn't have time to implement , but if you have time to implement them or even add more cool features, please notify me as well :). you can find me here http://sina.salek.ws/en/contact

PS : It was very useful for me, hope you find it useful as well.

<?php

/**

* Copy file or folder from source to destination, it can do

* recursive copy as well and is very smart

* It recursively creates the dest file or directory path if there weren't exists

* Situtaions :

* - Src:/home/test/file.txt ,Dst:/home/test/b ,Result:/home/test/b -> If source was file copy file.txt name with b as name to destination

* - Src:/home/test/file.txt ,Dst:/home/test/b/ ,Result:/home/test/b/file.txt -> If source was file Creates b directory if does not exsits and copy file.txt into it

* - Src:/home/test ,Dst:/home/ ,Result:/home/test/** -> If source was directory copy test directory and all of its content into dest

* - Src:/home/test/ ,Dst:/home/ ,Result:/home/**-> if source was direcotry copy its content to dest

* - Src:/home/test ,Dst:/home/test2 ,Result:/home/test2/** -> if source was directoy copy it and its content to dest with test2 as name

* - Src:/home/test/ ,Dst:/home/test2 ,Result:->/home/test2/** if source was directoy copy it and its content to dest with test2 as name

* @todo

* - Should have rollback technique so it can undo the copy when it wasn't successful

* - Auto destination technique should be possible to turn off

* - Supporting callback function

* - May prevent some issues on shared enviroments : http://us3.php.net/umask

* @param $source //file or folder

* @param $dest ///file or folder

* @param $options //folderPermission,filePermission

* @return boolean

*/

function smartCopy($source, $dest, $options=array('folderPermission'=>0755,'filePermission'=>0755))

{

$result=false;

if (

is_file($source)) {

if (
$dest[strlen($dest)-1]=='/') {

if (!
file_exists($dest)) {

cmfcDirectory::makeAll($dest,$options['folderPermission'],true);

}

$__dest=$dest."/".basename($source);

} else {

$__dest=$dest;

}

$result=copy($source, $__dest);

chmod($__dest,$options['filePermission']);

} elseif(

is_dir($source)) {

if (
$dest[strlen($dest)-1]=='/') {

if (
$source[strlen($source)-1]=='/') {

//Copy only contents

} else {

//Change parent itself and its contents

$dest=$dest.basename($source);

@
mkdir($dest);

chmod($dest,$options['filePermission']);

}

} else {

if (
$source[strlen($source)-1]=='/') {

//Copy parent directory with new name and all its content

@mkdir($dest,$options['folderPermission']);

chmod($dest,$options['filePermission']);

} else {

//Copy parent directory with new name and all its content

@mkdir($dest,$options['folderPermission']);

chmod($dest,$options['filePermission']);

}

}
$dirHandle=opendir($source);

while(
$file=readdir($dirHandle))

{

if(
$file!="." && $file!="..")

{

if(!
is_dir($source."/".$file)) {

$__dest=$dest."/".$file;

} else {

$__dest=$dest."/".$file;

}

//echo "$source/$file ||| $__dest<br />";

$result=smartCopy($source."/".$file, $__dest, $options);

}

}

closedir($dirHandle);

} else {

$result=false;

}

return
$result;

}

?>

jtaylor -at- ashevillenc -dot- com

16 years ago

It seems as though you can only use move_uploaded_file() once on a temporary file that has been uploaded through a form. Most likely the action this function takes destroys the temporary file after it has been moved, assuming permanent placement on a file system.

Attempting to use the function again in the same PHP script will return false and not move the file.

I ran into this when an image that was uploaded did not need resizing (smaller than a size threshold) and after moving the temporary upload to the "originals" directory, an attempt was made to again move the temporary file to another folder.

This behavior is understandable, but be careful - in this instance, I simply used copy() on the file that was already uploaded.

allasso residing at signalmesa dot com

14 years ago

As far as recursive copy, something like this seems to work fine for me:

<?php
$output
= shell_exec( " cp -r -a dir_source/* dir_dest 2>&1 " )
echo
$output
?>

Of course you need to get all your permissions clear. You can do the necessary stuff to use variables.

You could also do this to create the destination directory:

<?php
shell_exec
( " cp -r -a dir_source dir_dest 2>&1 " )
?>

This will create a new directory called "dir_dest" if it does not already exist. This is a bit risky though if your situation is ambiguous, and you want to continue to make backups etc, 'cause if you do it twice you end up with:

dir_destination/dir_source

to avoid that one could do something like:

<?php
shell_exec
( " mkdir dir_dest; cp -r -a dir_source/* dir_dest 2>&1 " )
?>

Maybe someone can tell me when or why it would be better to use all that PHP code I see here.

Anonymous

5 months ago

If you get ssl errors for apps running on an unproperly configured server and have no way to fix the server configuration, this would be a temproraly workaround.
//Disable ssl verification in order to avoid ssl error
$contextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),);
copy($filename, $attachFileName,stream_context_create($contextOptions));

2mobile at gmail dot com

6 years ago

If you have problems with "failed to open stream: Permission denied"

Check if the user that PHP runs under have "X" permission on every directory of the file path.
It will need it to access the file

If your file is: /path/to/test-in.txt
You should have X permission on:

/path
/path/to
and read permission on /path/to/test-in.txt

nensa at zeec dot biz

14 years ago

When I recently had to copy a few millions of small files (< 1kb) from one NAS to another and for some reasons had to do that file by file I compared the following function with copy($src, $dest) and shell_exec("cp -r $src $dest").

Surprisingly stream_copy seamed to be slightly faster (at least in this specific context).

<?php

function stream_copy($src, $dest)

{

$fsrc = fopen($src,'r');

$fdest = fopen($dest,'w+');

$len = stream_copy_to_stream($fsrc,$fdest);

fclose($fsrc);

fclose($fdest);

return
$len;

}

?>

cory at veck dot ca

12 years ago

My own 'cp -R' written in PHP.

Hopefully it will work for your situation. I'm using it in a web based file manager for my CMS.

<?php

define

('DS', DIRECTORY_SEPARATOR); // I always use this short form in my code.function copy_r( $path, $dest )
{
if(
is_dir($path) )
{
@
mkdir( $dest );
$objects = scandir($path);
if(
sizeof($objects) > 0 )
{
foreach(
$objects as $file )
{
if(
$file == "." || $file == ".." )
continue;
// go on
if( is_dir( $path.DS.$file ) )
{
copy_r( $path.DS.$file, $dest.DS.$file );
}
else
{
copy( $path.DS.$file, $dest.DS.$file );
}
}
}
return
true;
}
elseif(
is_file($path) )
{
return
copy($path, $dest);
}
else
{
return
false;
}
}
?>

mspreij

16 years ago

This function creates a new filename to use for a copy of the given filename, its behaviour was mostly sto^Wborrowed from how the OS X Finder (*1) does it.

Note it *doesn't* actually copy the file, it just returns the new name. I needed it to work regardless of data source (filesystem, ftp, etc).

It also tries to match the current name as neatly as possible:

foo.txt -> foo copy.txt -> foo copy 1.txt -> foo copy 2.txt [etc]

foo.bar.baz.jpg -> foo.bar.baz copy.jpg

foobar -> foobar copy -> foobar copy 1 [etc]

".txt" -> .txt copy, and "txt." -> txt. copy

file.longextension -> file.longextension copy

It keeps trying until it finds a name that is not yet taken in $list, or until it looped 500 times (change as needed).

If the renamed file becomes longer than max filename length, it starts chopping away at the end of the part before where it adds " copy": reallylong...filename.txt -> reallylong...filena copy.txt

<?php
// $orig = current name, of course

// $list = array of filenames in the target directory (if none given, it will still return a new name)

// $max = max length of filename

function duplicate_name($orig, $list = array(), $max = 64) {

$ext = '';

$counter = 0;

$list = (array) $list;

$max = (int) $max;

$newname = $orig;

do {

$name = $newname; # name in, newname out

if (preg_match('/ copy$| copy \d+$/', $name, $matches)) {

// don't even check for extension, name ends with " copy[ digits]"

// preg hereunder matches anything with at least one period in the middle and an extension of 1-5 characters

}elseif (preg_match('/(.+)\.([^.]{1,5})$/', $name, $parts)) {

// split to name & extension

list($name, $ext) = array($parts[1], $parts[2]);

}

if (
preg_match('/ copy (\d+)$/', $name, $digits)) {

$newname = substr($name, 0, - strlen($digits[1])) . ($digits[1] + 1);

# $cutlen is only used for the bit at the end where it checks on max filename length

$cutlen = 6 + strlen($digits[1]+1); // ' copy ' + digits

}elseif(preg_match('/ copy$/', $name, $digits)) {

$newname = $name . ' 1';

$cutlen = 7; // ' copy' + ' 1'

}else{

$newname = $name . ' copy';

$cutlen = 5; // ' copy'

}

if (
$ext) {

$newname .= '.' . $ext;

$cutlen += strlen($ext) + 1;

}

if (
$max > 0) {

if (
strlen($newname) > $max) {

$newname = substr($newname, 0, max($max - $cutlen, 0)) . substr($newname, -$cutlen);

if (
strlen($newname) > $max) {echo "duplicate_name() error: Can't keep the new name under given max length.\n"; return false;}

}

}

if (
$counter++ > 500) {echo "duplicate_name() error: Too many similarly named files or infinite while loop.\n"; return false;}

} while (
in_array($newname, $list));

return
$newname;

}
?>



*1) The Finder seems to check the extension vs a list of known extensions, this function considers it valid if it's 5 or fewer characters long.

ps. sorry for taking up so much space! :-)

mishawagon at gmail dot com

4 years ago

Copy failed for me until I added dirname(__FILE__) to the file paths.
copy(dirname(__FILE__).$tempdata,dirname(__FILE__).$filepath)

I’m getting error while using php function copy()

Warning: copy() [function.copy]:
Couldn’t resolve host name in

Warning:
copy(http://www.foodtest.ru/images/big_img/sausage_3.jpg)
[function.copy]: failed to open
stream: operation failed in

what’s wrong with that url?

asked Mar 3, 2011 at 0:33

Tuco's user avatar

4

Try enclosing the url withing quotes «».

answered Mar 3, 2011 at 0:36

Raja's user avatar

RajaRaja

4425 silver badges17 bronze badges

2

Try plugging in a destination argument and make sure to have the soft ticks around the arguments.

copy("http://www.foodtest.ru/images/big_img/sausage_3.jpg", "./file.jpg");

answered Mar 3, 2011 at 0:37

a.stgeorge's user avatar

a.stgeorgea.stgeorge

3041 silver badge7 bronze badges

8

a little old, but important to pay attention, in case this helps someone who gets here:

copy command is folder-case sensitive, so if you try to copy 1.jpg from a folder called «ThumbImages» like that:

copy("thumbimages/1.jpg","[destination...]")

it will not find the folder.

notice you are using upper or lower case that matches the folder name

  • I just reached this post while trying to figure out an issue and now that it is solved, I hope it will help others.

answered Jun 14, 2017 at 15:43

marble's user avatar

I have task to copy my file from a folder to the current one. But when I perform this I get the following error:

Warning:  copy(C:/wamp/www/dfms/) [function.copy]: failed to open stream:
Permission denied in C:\wamp\www\dfms\docShow.php on line 646

The code is given below

if (copy('images/uploads/'.$doclisting['docfile_name'], 'C:/wamp/www/dfms/'))
{
  echo "Pranav";
}

I also tried by using chmod 0777 but still it gives me same error

hakre's user avatar

hakre

194k52 gold badges436 silver badges836 bronze badges

asked Mar 11, 2011 at 11:19

OM The Eternity's user avatar

OM The EternityOM The Eternity

15.7k44 gold badges120 silver badges182 bronze badges

You are on a windows server, which means that chmod 0777 will probably not do much.

What you need to do is give Apache the permission to write to C:/wamp/www/dfms/ — doing so the windows way.

Not sure about a Windows server, but I’m guessing right-clicking on that directory, choosing Properties, findind some «permission» or «security» tab, and checking some checkbox that corresponds to «write» for the correct user should do the trick.

answered Mar 11, 2011 at 11:22

Pascal MARTIN's user avatar

Pascal MARTINPascal MARTIN

395k80 gold badges655 silver badges663 bronze badges

Have you tried adding the filename to the destination?

Like so:

if(copy('images/uploads/'.$doclisting['docfile_name'],'C:/wamp/www/dfms/'.$doclisting['docfile_name']))
  {
    echo "Pranav";
  }

answered Mar 11, 2011 at 11:24

Alex Bailey's user avatar

1

chmod 0777 is a unix command, I’d be curious how you successfully tried this on windows.

Check these file and directory access control. You should make sure that the webserver process/user has the rights to this directory.

answered Mar 11, 2011 at 11:21

Evert's user avatar

EvertEvert

93.6k18 gold badges118 silver badges189 bronze badges

0

Make sure you have «allow_url_fopen = On» in your php.ini

The php.ini file is where you declare changes to your PHP settings. You can edit the existing php.ini, or create a new text file in any subdirectory and name it php.ini.

answered Aug 15, 2018 at 2:47

Christian O's user avatar

  • #1

Функция copy не копирует =)

Д.день!
Пытаюсь закачать файл следующим кодом:

PHP:

                if (is_uploaded_file($_FILES['filename_small']['tmp_name']))
                   {
                   $_FILES['filename_small']['name']=strtolower($_FILES['filename_small']['name']);
                   if(!file_exists("$CFG->dirroot/images/enlarge_news_foto/".$_FILES['filename_small']['name']))
                       {
                       if(!ereg("^[a-z0-9._-]{1,255}$",$_FILES['filename_small']['name']))
  		       {
	                       $info_message="Имя файла '".$_FILES['filename_small']['name']."' в поле 'Фото' содержит недопустимые символы. Имя фаила должно состоять из a-z, 0-9, и символов '.', '_', '-'. Переименуйте файл перед загрузкой в новость.";
        	               return 1;
		       }
                       $f_s=$_FILES['filename_small']['name'];

		       if(!copy($_FILES['filename_small']['tmp_name'], "$CFG->dirroot/images/enlarge_news_foto/".$_FILES['filename_small']['name']))			{
			echo "<BR>НЕ УДАЛОСЬ СКОПИРОВАТЬ ФАЙЛ!<BR>";
			}
                       
                   else
                       {
                       $info_message="Файл с именем ".$_FILES['filename_small']['name']." уже существует. Измените имя фаила для поля 'фото'.";
                       return 1;
                       }
                   }

До момента использования функции copy все шикарно, но вот на функции процесс встает. Она возвращает false.
у меня — error_reporting(E_ALL);
Сообщений об ошибках не вылетает…
Помогите как-нибудь пжалуйста =)

  • #2

>> Сообщений об ошибках не вылетает…
Ты ЛОГ смотришь?
Или у тебя ini_set(‘display_errors’, 1)?

  • #3

эээ… лог не смотрю=) А где его посмотреть? (простите за незнание=)
«ini_set(‘display_errors’, 1)» — Такого нет.

-~{}~ 28.09.05 17:04:

вставил предложенную функцию. Получил ошибку:

Warning: copy(http://www.xxx.ru/images/enlarge_news_foto/water_lil.jpg): failed to open stream: HTTP wrapper does not support writeable connections. in /home/httpd/vhosts/xxx.ru/httpdocs/admin/news.php on line 208

  • #4

>> Такого нет.
Ну вот поставь это временно перед приведённым кодом, — авось и сообщение об ошибке покажется.

  • #6

Вот…
Почему 2-й параметр в copy — URI, а не путь в файловой системе?

  • #7

ТАААК… потому что я торможу… тестил кое-что и не исправил=)
Ошибка после того как руки были вкручены на место:
Warning: copy(/home/httpd/vhosts/ххх.ru/httpdocs/images/enlarge_news_foto/water_lil.jpg): failed to open stream: Permission denied in /home/httpd/vhosts/ххх.ru/httpdocs/admin/news.php on line 208

  • #8

«Permission denied» переведёшь?

  • #9

вряд ли сумею =) А это запрет на запись в каталог? Нужно на скрипте права задать или на каталог?
на скрипте у меня — 644

Не судите слишком строго я сегодня тормоз =)

  • #10

Можно начать с попытки разрешить запись в каталог, куда ты хочешь копировать скриптом файл.

  • #11

на каталог куда собираешься записывать

  • #12

на всей ветви каталогов стоят 755… Уж не знаю что и делать… Вроде должно хватать!

  • #13

>> Вроде должно хватать!
Я плохо в этом разбираюсь, но, по-моему, это не так.

  • #14

хм… я всегда надеялся, что хоть в этом я разбираюсь =) Народ, кто разбирается, помогите взрослым дядям =)) !!!

P.S. Просто самая большая ботва в том, что раньше работало, а потом перестало резко =) Я думал, что я что-то где-то накодил криво, да вроде все в норме.

P.P.S. Я конечно выставил права 757 — при этом работает, но… что-то меня смущают проблемы безопасности этого действа =(

Понравилась статья? Поделить с друзьями:
  • Copperbeard sea of thieves ошибка
  • Coop land ошибка
  • Coolomet глупые ошибки
  • Coolant low stop engine ошибка вольво s60
  • Coolant temperature ошибка