★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.copy.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to ファイルシステム
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
ファイルシステム
* basename
* chgrp
* chmod
* chown
* clearstatcache
* copy
* delete
* dirname
* diskfreespace
* fclose
* feof
* fgetc
* fgetcsv
* fgets
* fgetss
* file
* file_exists
* fileatime
* filectime
* filegroup
* fileinode
* filemtime
* fileowner
* fileperms
* filesize
* filetype
* flock
* fopen
* fpassthru
* fputs
* fread
* fscanf
* fseek
* fstat
* ftell
* ftruncate
* fwrite
* set_file_buffer
* is_dir
* is_executable
* is_file
* is_link
* is_readable
* is_writeable
* link
* linkinfo
* mkdir
* pclose
* popen
* readfile
* readlink
* rename
* rewind
* rmdir
* stat
* lstat
* realpath
* symlink
* tempnam
* touch
* umask
* unlink
Manual: copy
View the source code for this pageSearch the site



Previous page
 clearstatcache
 Updated
Sat, 12 Aug 2000
delete 
Next page


copy

(PHP3 , PHP4 )

copy -- ファイルをコピーする

説明

int copy (string source, string dest)

ファイルのコピーを作成します。コピーが成功するとtrue、 そうでなければfalseを返します。

例 1. copy()の例


if (!copy($file, $file.'.bak')) {
    print("$file へのコピーに失敗しました...<br>\n");
}
      

rename()も参照下さい。


User Contributed Notes: copy


greywire@peoplecatcher.com
20-Mar-2000 03:41
I was wondering the same thing. so far, I am just fopen()'ing the file and doing read/write to the local file. Like so:

<pre>
if (!($fp = fopen($srcfile,"r"))) die("Could not open src");
if (!($fp2 = fopen($file,"w"))) die("Could not open dest");

while ($contents = fread( $fp, 4096 )) {
fwrite( $fp2, $contents, strlen($contents) );
}
fclose($fp);
fclose($fp2);

</pre>

Just to be a little more clear on the above... the $srcfile is a URL (in my case, it's "http://www.slashdot.org/slashdot.xml" but it could be an FTP or any other proper URL)



waller@choiceoneonline.com
25-Apr-2000 01:13
Here is some useful notes on my experience with copy
<pre>
$path ="../../images/press";
// copying image
if ($image_type == "image/pjpeg") {
copy($image,$path.$image.".jpg");
$name = $image;
$name.=".jpg";
}
</pre>

Manipulate as needed :)



joe@koontz.net
19-Jul-2000 10:00
To serve a file to a client from the server you can do this: (This also enables dynamic file content just by altering what is echo'd out)
<pre>
<?
$fp = fopen("file.x","r");
$buff = fread($fp,1000000);
Header("Content-Type: application/x-octet-stream");
// you can put the header file-length here but I never use it!
Header("Content-Disposition: attachment; filename=DOWNLOADEDFILENAMEHERE"); echo $buff;
</pre>
this will trigger the download action.
joe



brooke@jump.net
27-Jul-2000 02:57
To people asking how to copy files to and from the server and client:

Look at the PHP documentation under features/handling files uploads.
http://www.php.net/manual/features.file-upload.php

There you will find how to get a file from the client to the server via HTTP and a web browser.

The other direction (Server to client) has been addressed before, but look in the section on readfile:
http://www.php.net/manual/function.readfile.php
It will tell you the easy way.



 About Notes


Previous page
 clearstatcache
 Updated
Sat, 12 Aug 2000
delete 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.