473,729 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ha ndle))
{
$filetyp = strtolower(subs tr($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_h andle);

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 8117
On 22 Jan 2007 20:30:05 -0800, "eholz1" <ew****@gmail.c omwrote:
>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_ha ndle))
{
$filetyp = strtolower(subs tr($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_h andle);

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.c omwrote:
>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_ha ndle))
{
$filetyp = strtolower(subs tr($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_ha ndle))
{
$filetyp = strtolower(subs tr($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_h andle);

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*******@attgl obal.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_ha ndle))
{
$filetyp = strtolower(subs tr($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_h andle);

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*******@attgl obal.net
=============== ===
Jan 23 '07 #5

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

Similar topics

1
6079
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 original destination IP address and tcp port? On FreeBSD I just use ipfw and fwd and then following works: $daddr=$client->sockhost; $dport=$client->sockport;
3
2374
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 provider's SQL Server database on the back-end. Is there a way to export tables from one SQL Server database to another in such a way that if a table already exists in the destination database, it will be updated to reflect the changes to the local...
2
4624
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 etc) from a XML file to move files across the internal network to a different domain. This is a console application that should have the option of specifying the parameters at the commandline prompt. When I specify the parameters at cmd line, it...
7
1552
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 MyArray as classNewArray MyArray.add("Data1", "Data2") or the looping claus....
12
2369
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 text</a> . Could be further complicated by the ASP and SQL designation of URL. like: http://sampleURL.org/FAQs.asp?FAQMID=11&NumFaq=10&bmode=Main W3C validator said 91 errors, mostly on tables, fonts and graphics, but didn't seem to complain about...
16
14498
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
5432
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, 21:00:14) 20040728] on freebsd5 Type "help", "copyright", "credits" or "license" for more information. usage:copy source destination
13
6617
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
1154
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) ================ ID Name
1
5935
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 error. Here is the function: function UploadSingleImage($imageid,$maxsize,$putinto){ //uploads a single file. $return=30;//if all success, the func returns 30 global $photoerr; $kb=($maxsize/1024)." KB";
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.