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
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().

Link to comment
Share on other sites

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
}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.