• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

php copy not working

Good afternoon,
Ive written what I thought to be a simple program to copy a file to a network server and then copy it back. Issue is it doesnt seem to copy the file, but it also doesnt show any errors!!!

The code I have is:-
<?php

if (isset($_GET['testDest'])==false)
{
	echo "No testDest set in GET";
	exit();	
}
set_time_limit(0); 
error_reporting(-1);


echo "Generating File <br> \n";
$randFile = "myFile_" . rand(0,9999) . ".dat";

$fh = fopen($randFile, 'w') or die("can't open file");
$stringData = chr(rand(1,255));
fwrite($fh, $stringData);
fclose($fh);

while (filesize($randFile) < 100000)
	{
	
	$fh = fopen($randFile, 'a') or die("can't open file");
	$stringData = "";
	for ($x=1;$x<=1000;$x++)
	{
		$stringData = $stringData . chr(rand(1,255)) . chr(rand(1,255)) . chr(rand(1,255)) . chr(rand(1,255)) . chr(rand(1,255)) . chr(rand(1,255)) . chr(rand(1,255)) . chr(rand(1,255));	
	}
	fwrite($fh, $stringData);
	fclose($fh);
	clearstatcache();
	}
	
	
echo "File generated, giving size of " . filesize($randFile) . "<br> \n";

function copyFile($randFile, $strSource)
	{
	echo "Starting to copy file to at " . date("Y-m-d H:i:s.u") . "<br> \n";
	$startTime = microtime(true);
	copy($randFile,$strSource);
	echo "Completed copying file to at " . date("Y-m-d H:i:s.u") . "<br> \n";
	echo "Time Taken was " . (microtime(true) - $startTime) . "<br> \n";
	



	$tmpFile = "myFile_" . rand(0,9999) . ".tmp";
	
	echo "Starting to copy file from at " . date("Y-m-d H:i:s.u") . "<br> \n";
	$startTime = microtime(true);
	copy($strSource, $tmpFile);
	echo "Completed copying file from at " . date("Y-m-d H:i:s.u") . "<br> \n";
	echo "Time Taken was " . (microtime(true) - $startTime) . "ms <br> \n";
	//unlink($tmpFile);
	//unlink($strSource);
	echo "<br> \n <HR> <br> \n";
	}

//copyFile($randFile, "\\\\172.16.8.7\\Public\\" . $randFile);


echo "Testing " . $_GET['testDest'] . "<BR>\n";
copyFile($randFile, $_GET['testDest'] . $randFile);

set_time_limit(30);

//unlink($randFile);	
?>

Open in new window


Which generates the output:-
Generating File 
File generated, giving size of 104001
Testing \\172.16.8.7\Public\
Starting to copy file to at 2011-05-06 15:30:32.u
Completed copying file to at 2011-05-06 15:30:32.u
Time Taken was 0.001579
Starting to copy file from at 2011-05-06 15:30:32.u
Completed copying file from at 2011-05-06 15:30:32.u
Time Taken was 0.001537ms 

Open in new window


So as you can see there is no error, but it doesnt copy the file either to or from?

Any assistance?
0
tonelm54
Asked:
tonelm54
  • 4
  • 2
1 Solution
 
Ray PaseurCommented:
Let's start by adding these to the script:

ini_set('display_errors', TRUE);
error_reporting(E_ALL);
0
 
tonelm54Author Commented:
Whats intresting is it is creating a file on my server where this is running as "\\172.16.8.7\Public\myFile_8959.dat" which is the file its supposed to copy to
0
 
Ray PaseurCommented:
Next let's test the return from copy().  Check the man page for how to do that:
http://php.net/manual/en/function.copy.php
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
After that about all I can recommend is that you use some data visualization.  For that to be effective, reconsider how you write some of the PHP instructions.  Example from line 64:

copyFile($randFile, $_GET['testDest'] . $randFile);

Instead you might do something like this:

$new = $_GET['testDest'] . $randFile;
echo "<pre>";
echo PHP_EOL;
echo $randFile;
echo PHP_EOL;
echo $new;
copyFile($randFile, $new);
0
 
tonelm54Author Commented:
Ive added to my code:-
            ini_set('display_errors', TRUE);
            error_reporting(E_ALL);

Same output, apart from slightly different times:-
Generating File 
File generated, giving size of 104001
Testing \\172.16.8.7\Public\
Starting to copy file to at 2011-05-06 15:43:30.u
Completed copying file to at 2011-05-06 15:43:30.u
Time Taken was 0.001534
Starting to copy file from at 2011-05-06 15:43:30.u
Completed copying file from at 2011-05-06 15:43:30.u
Time Taken was 0.001501ms 

Open in new window

0
 
Ray PaseurCommented:
http://www.laprbass.com/RAY_temp_tonelm54.php
generates
http://www.laprbass.com/RAY_temp_tonelm54.txt

Does that help some? ~Ray
<?php // RAY_temp_tonelm54.php.php
error_reporting(E_ALL);


// CREATE A FILE OF RANDOM CHARACTERS OF A FIXED LENGTH


// THE LENGTH
$len = 128;

// THE DATA SET NAME
$dsn = 'RAY_temp_tonelm54.txt';

// THE CHARACTER SET
$set = range('A', 'Z');

// CREATE THE STRING
$str = NULL;
while (strlen($str) <= $len)
{
    // A RANDOMIZATION
    shuffle($set);
    $str .= end($set);
}

// SHOW THE STRING
echo $str;

// WRITE THE STRING
file_put_contents($dsn, $str);

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now