Member Avatar for gamefreak5678

I'm wanting to copy a file from one location to another using variables. This doesn't work and I can't figure out why. Is there more code that I need besides what's listed below?

copy("../upload/".$img,"../gallery/pic/".$img)

Debug with this below code.
post your output and current error you are getting.

<?	
	$source = "../upload/".$img;
	$destination = "../gallery/pic/".$img;
	
	if(file_exists($source))
		echo '<br />Source exists'.$source;
	if(file_exists($destination))
		echo '<br />Destination exists'.$destination;
		
	copy($source , $destination);
?>

hi
suppos $path="images/test.jpg";
when you are using file_exists $path and it returns true and you are using <img src='.$path it not show or when you are using file_exists return true but when you are try to include same file error no file apeared
note:
try to use file exist by path=images/test.jpg and if exists use with "/" /images/test.jpg

if you are submitting form html try move_uploadedfile command on php
use "/" in first of path to point public_html it is more important when you are use mode re write all of images and css path change to /images/logo.jpg and /templates/green/style.css (sample of joomla theme )

and alwais use @ in first of command to handle errors: see
$ok=@main();
if($ok){echo('yes');}else{echo 'no';}
or
$ok=@copy()
$ok=@move_uploadedfile()
------- note that move_uploaded files is better from copy because copy make duplicate file in folder tmp and your target
for delete file use unlink after copy
$deleted=@unlink($path);
-------- im with iran and sorry for my bad english us writting. thanks.

Member Avatar for gamefreak5678

Debug with this below code.
post your output and current error you are getting.

<?	
	$source = "../upload/".$img;
	$destination = "../gallery/pic/".$img;
	
	if(file_exists($source))
		echo '<br />Source exists'.$source;
	if(file_exists($destination))
		echo '<br />Destination exists'.$destination;
		
	copy($source , $destination);
?>

Warning: copy(../upload/2555865893.jpg) [function.copy]: failed to open stream: No such file or directory in /home/content/00/6550000/html/upload_result.php on line 35

EDIT: There isn't an output, just that error

Member Avatar for gamefreak5678

hi
suppos $path="images/test.jpg";
when you are using file_exists $path and it returns true and you are using <img src='.$path it not show or when you are using file_exists return true but when you are try to include same file error no file apeared
note:
try to use file exist by path=images/test.jpg and if exists use with "/" /images/test.jpg

if you are submitting form html try move_uploadedfile command on php
use "/" in first of path to point public_html it is more important when you are use mode re write all of images and css path change to /images/logo.jpg and /templates/green/style.css (sample of joomla theme )

and alwais use @ in first of command to handle errors: see
$ok=@main();
if($ok){echo('yes');}else{echo 'no';}
or
$ok=@copy()
$ok=@move_uploadedfile()
------- note that move_uploaded files is better from copy because copy make duplicate file in folder tmp and your target
for delete file use unlink after copy
$deleted=@unlink($path);
-------- im with iran and sorry for my bad english us writting. thanks.

I'm not moving a file right after it has been uploaded. If the file is already there, can I still use that function?

Check folder permission and run below code and post output.
I think the file you want to copy is not there in source folder.

<?	
	$source = "../upload/".$img;
	$destination = "../gallery/pic/".$img;
	
	if(file_exists($source))
		echo '<br />Source exists:'.$source;
	else
		echo '<br />Source not exists:'.$source;
	
	if(file_exists($destination))
		echo '<br />Destination exists:'.$destination;
	else
		echo '<br />Destination not exists:'.$destination;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.