php copy command not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mtb211
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2008 11:32 am

php copy command not working

Post by mtb211 »

Here is the error im receiving and below I posted the code for line 55


Warning: mkdir(qwa): File exists in /var/www/vhosts/punktewolke.de/httpdocs/kunden/erstell.php on line 20

Warning: copy(/var/www/vhosts/punktewolke.de/httpdocs/qwa/index.php): failed to open stream: No such file or directory in /var/www/vhosts/punktewolke.de/httpdocs/kunden/erstell.php on line 55
failed to copy ...


Code: Select all

 
if (!copy($_SERVER['DOCUMENT_ROOT'] . '/kunden/muster/index.php', $_SERVER['DOCUMENT_ROOT'] . '/' . $dir.'/index.php')) {
    echo ("failed to copy $file...<br>\n");
}
 
ive edited this code like crazy but im still receiving the same error, any ideas?

Matt

Image
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: php copy command not working

Post by pcoder »

Are you sure the file is in the appropriate location?
mtb211
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2008 11:32 am

Re: php copy command not working

Post by mtb211 »

hey coder, i sent a screen shot (just a minute ago.. I modified my post .. I put [copy] instead of

Code: Select all

.. )

I believe its in the correct place, i could be making a huge novice error

thanks for the help!
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: php copy command not working

Post by pcoder »

An another likely cause is the file permission.Check out the file permission. Permission lower than 644 may be problematic.
mtb211
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2008 11:32 am

Re: php copy command not working

Post by mtb211 »

it was on 644 and now I changed it to 777... still have an error

hmm..
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: php copy command not working

Post by pcoder »

Code: Select all

$_SERVER['DOCUMENT_ROOT'] . '/' . $dir.'/index.php'
In this destination location, where does this $dir comes from. Please be sure with the upper/lower case also.
mtb211
Forum Newbie
Posts: 15
Joined: Sun Dec 14, 2008 11:32 am

Re: php copy command not working

Post by mtb211 »

Hey coder,

thanks for helping me out

Are you talking about where I declare?

Code: Select all

 
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
 
<?php 
 
$dir = $uname; 
$user = $_POST['user']; 
$pass = $_POST['pass']; 
 
// Aktuelles Verzeichnis ermitteln 
$thisdir = str_replace(strrchr($_SERVER['SCRIPT_FILENAME'],'/'), '', $_SERVER['SCRIPT_FILENAME']); 
 
// Gewünschtes Verzeichnis erstellen 
$oldumask = umask(0);
mkdir($dir,0777); 
 umask($oldumask);
// Daten für .htaccess erstellen 
$htaccess = 'AuthType Basic 
AuthUserFile '.$thisdir.'/'.$dir.'/.htpasswd 
AuthName "Enter user name and password please!" 
order deny,allow 
allow from all 
require valid-user'; 
 
// Daten für .htpasswd erstellen 
$htpasswd = $uname.':'.crypt($pw, substr(md5(uniqid(rand())), 0, 2)); 
 
// Testdatei erstellen (wird angezeigt beim erfolgreichen Login) 
/*
$handle = fopen($dir.'/index.php', 'w'); 
fwrite($handle, '
 
<? 
echo "Hier sind die Bereitgestellten Dateien<br><br>";
$action=opendir("./");
while($datei=readdir($action)){ 
if(!preg_match("!(\.|\..)$!", $datei)){ 
if ($datei!="index.php" && $datei!=".htaccess" && $datei!=".htpasswd" ) { 
echo "
<a href=\"$datei\"> 
 
$datei</a><br>"; } } } ?>'); 
fclose($handle); 
 
// .htaccess erstellen 
$handle = fopen($dir.'/.htaccess', 'w'); 
fwrite($handle, $htaccess); 
fclose($handle); 
*/
if (!copy($_SERVER['DOCUMENT_ROOT'] . '/kunden/muster/index.php', $_SERVER['DOCUMENT_ROOT'] . '/' . $dir.'/index.php')) {
    echo ("failed to copy $file...<br>\n");
}
 
 
// .htpasswd erstellen 
$handle = fopen($dir.'/.htpasswd', 'w'); 
fwrite($handle, $htpasswd); 
fclose($handle); 
 
?> 
</body>
</html>
 
it looks like everything is okay :) I hate syntax errors
Post Reply