legohead6 Posted January 23, 2008 Share Posted January 23, 2008 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"; Quote Link to comment https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/ Share on other sites More sharing options...
KrisNz Posted January 23, 2008 Share Posted January 23, 2008 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(). Quote Link to comment https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/#findComment-447314 Share on other sites More sharing options...
legohead6 Posted January 23, 2008 Author Share Posted January 23, 2008 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 } Quote Link to comment https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/#findComment-447319 Share on other sites More sharing options...
legohead6 Posted January 23, 2008 Author Share Posted January 23, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/#findComment-447324 Share on other sites More sharing options...
KrisNz Posted January 23, 2008 Share Posted January 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/#findComment-447330 Share on other sites More sharing options...
legohead6 Posted January 23, 2008 Author Share Posted January 23, 2008 ya the file has been uploaded already in previous forms... ill try rename WORKS LIKE A CHARM! THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/87460-solved-if-copy-failed-dont-continue/#findComment-447333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.