473,379 Members | 1,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

copy($source, $destination) not working for me

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>';
}

$idx++;
$filecount++;

}
}

closedir($dir_handle);

echo '<h2>'."counted: " . $filecount . " files.".'</h2>';

?>
I have tried to copy to the same directory as well - no luck. the
webserver has access to the folders in question. What do I need to do
to get this to work?

Thanks Again,

eholz1

Jan 23 '07 #1
4 8081
On 22 Jan 2007 20:30:05 -0800, "eholz1" <ew****@gmail.comwrote:
>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>';
}

$idx++;
$filecount++;

}
}

closedir($dir_handle);

echo '<h2>'."counted: " . $filecount . " files.".'</h2>';

?>
I have tried to copy to the same directory as well - no luck. the
webserver has access to the folders in question. What do I need to do
to get this to work?

Thanks Again,

eholz1
Permissions problem? On Apache *nix servers, PHP generally runs as
"nobody". Try to chmod 777 the directory to see if thast solves the
problem.
Jan 23 '07 #2
"eholz1" <ew****@gmail.comwrote:
>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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jan 23 '07 #3
eholz1 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>';
}

$idx++;
$filecount++;

}
}

closedir($dir_handle);

echo '<h2>'."counted: " . $filecount . " files.".'</h2>';

?>
I have tried to copy to the same directory as well - no luck. the
webserver has access to the folders in question. What do I need to do
to get this to work?

Thanks Again,

eholz1
In addition, remove the '@' from the copy command and see what error you
get. It will help your troubleshooting.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '07 #4
Hello All,

As always the PHP group comes through! I will check all these options
out.

Thanks

eholz1
If I get the copy copying i will advise.
Thanks again,

eholz1

Jerry Stuckle wrote:
eholz1 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>';
}

$idx++;
$filecount++;

}
}

closedir($dir_handle);

echo '<h2>'."counted: " . $filecount . " files.".'</h2>';

?>
I have tried to copy to the same directory as well - no luck. the
webserver has access to the folders in question. What do I need to do
to get this to work?

Thanks Again,

eholz1

In addition, remove the '@' from the copy command and see what error you
get. It will help your troubleshooting.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lincoln Yeoh | last post by:
Sorry to repost this but I still haven't figured it out and there weren't any responses. --- Say I use iptables to redirect tcp connections to my perl proxy servers. How then do I get the...
3
by: Bennett Haselton | last post by:
I'm working on an ASP.Net project where I want to test code on a local machine using a local database as a back-end, and then export it to the production machine where it uses the hosting...
2
by: Divya | last post by:
Hello, I am developing a simple move file utility to move files from one domain to another in the same internal network. My program runs fine when it reads the parameters (user, domain, password...
7
by: Peter | last post by:
I want to create a multidemensional arraylist. Seeing as they don't exist I was wondering if there is a way to create a class that works like one. I basically want to use it like this Dim...
12
by: Rich | last post by:
Strangely, on-page anchors will work on MSIE, but not on Netscape7.2 or Firefox1.5. All anchors are numbers e.g. <a href="#21">TOPIC</a> supposed to connect down to <a name="#21>beginning of...
16
by: Frances | last post by:
<a href="#1"> <a name="#1"> this link is not working in FF (works fine in IE..) would appreciate thoughts/suggestions.. thank you.. Frances
4
by: jiang.haiyun | last post by:
Hello all, when i import SOAPpy, the python crashed and print out 'usage:copy source destination'. As follows: ############################ haiyun# python Python 2.4.1 (#2, Mar 28 2006,...
13
by: Dave White | last post by:
Hello everyone, Is there some way to highlight the destination of a link such as a definition tag: <dt><a name="Definition">Definition</a></dt> Thanks in advance, Dave White
0
by: Hetal | last post by:
Hi.. I am working on VB.NET 2003 (windows form) application and using ADO.NET to deal with databases. The table structure i am working with is as follows. DB1.Table1 (source)...
1
by: samvb | last post by:
I tested it in my local development machine but it doesnt work in live server. move_uploaded_file just uploads jpg pictures of 60kb or less. It doesn't generate any error except my own custom...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.