Jump to content

[SOLVED] if copy() failed dont continue


legohead6

Recommended Posts

how would i do this, its for moving files and i want it so if it was unable to move the file it wont unlink() it.

 

$ftc2= explode('/', "$ftc");//break out the current folder name
$mm= $ftc2[1];
@copy("$dir/$ftc","$dir/$mm") OR die("Unable to Move File");
unlink("$dir/$ftc");
echo "File Successfully Moved to Main Folder";

Link to comment
https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/
Share on other sites

You've practically written the answer in your topic!

if (copy(....)) {
    echo "success";
    unlink("...");
} else {
    echo "unable to move file";
}

 

If you're just moving a file from one path to another, use rename().

If you're moving an uploaded file, use move_uploaded_file().

hmm i like that move_uploaded_file() command... so i dont need unlink when using that?

 

 

$ftc2= explode('/', "$ftc");//break out the current folder name
$mm= $ftc2[1];
if(move_uploaded_file ("$dir/$ftc","$dir/$mm")){
echo "File Successfully Moved to Main Folder";
}else{
echo "Unable to move File
}

 

 

I keep getting unable to move file with that code...

 

if(isset($_POST['sbtm'])){
$dir = "members/$user2";
$ftc=base64_decode($_GET['f']);
$ftct=$_POST['ftm'];
if($ftct == "main"){//if they want to move to main folder
$ftc2= explode('/', "$ftc");//break out the current folder name
$mm= $ftc2[1];
if(move_uploaded_file("$dir/$ftc","$dir/$mm")){
echo "File Successfully Moved to Main Folder";
}else{
echo "Unable to move File";
}
}else{//they dont want to move to main folder
if(move_uploaded_file("$dir/$ftc","$dir/$ftct/$ftc")){
echo "File Successfully Moved to Folder";
}else{
echo "Unable to move File";
}
}//end of which folder to move to

What is it you're trying to do? move_uploaded_file() moves files uploaded through a form, from the tmp directory to the destination you give. If that's not the case, use rename which moves the file from $source to $destination.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.