|
Posted by Tim Roberts on 01/23/07 07:26
"eholz1" <ewholz@gmail.com> wrote:
>Hello PHP group,
>
>I am trying to use the copy function to copy files from one directory
>to another.
>This does not seem to work for me. What am I missing?
>
>Below is the code I am using.
>
><?php
>$filecount = 0;
>$filelist[0] = '';
>$idx = 0;
>
> //define('loc1', '/usr/local/Apache2/htdocs/portfolios', true);
> $path = 'testimage';
> $thumb_path = 'thumbs';
>
> $dir_handle = @opendir($path) or die("Unable to open directory
>$path");
>
> //$filename2 = $filename . '.old';
> //copy($filename, $filename2);
>
>while ($file = readdir($dir_handle))
> {
> $filetyp = strtolower(substr($file, -3));
> if ($filetyp == 'jpg' )
> {
>//loc1. '/'.$path. '/' .$thumb_path . '/' .
> $filelist[$idx] = $path . '/' . $file;
> $thumbfile = $thumb_path . '/'. 'thumb-'. $file;
>
> if (!@copy($file, $thumbfile)) {
> echo "unable to copy file" .'<br>';
> }
Follow this through manually. readdir returns only the names of the files
in that directory, not the whole path. If the directory "testimage"
contains a file called "xxx.jpg", your copy command will expand to:
@copy( "xxx.jpg", "thumbs/thumb-xxx.jpg" )
See the problem? "xxx.jpg" doesn't exist in the current directory. It's
inside of "testimage".
You probably want
if( !@copy( $filelist[$idx], $thumbfile )) {
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Navigation:
[Reply to this message]
|