cabbie Posted June 14, 2013 Share Posted June 14, 2013 Why do I get error on move or copy? <?php $user = "joe";mkdir("members/$user", 0777);$srcfile='images/we.png'; $dstfile='members/$user/we.png'; $moveResult = move_uploaded_file($srcfile, $dstfile); if ($moveResult != true) {echo 'failed';exit();}//copy($srcfile, $dstfile) or die("Unable to copy $srcfile to $dstfile."); echo $srcfile, $dstfile, '?/'; ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 14, 2013 Share Posted June 14, 2013 Did you check the manual? This function expects a source file from a specific source. You seem to be simply assigning a name and attempting to move that. Quote Link to comment Share on other sites More sharing options...
louie35 Posted June 14, 2013 Share Posted June 14, 2013 Is the directory created and if YES, does it have the write permission 0777? Quote Link to comment Share on other sites More sharing options...
requinix Posted June 14, 2013 Share Posted June 14, 2013 Also, move_uploaded_file() only works on files in the $_FILES array. You can't use it to move any arbitrary file. Use rename instead. Quote Link to comment Share on other sites More sharing options...
cabbie Posted June 14, 2013 Author Share Posted June 14, 2013 (edited) I am trying to copy a default avatar pic to a users folder which is generated during activation The above code generates the folder I want to copy the default avatar to that folder in the users profile This is the activation code I just need the copy syntax.. <?php if(isset($_GET['user']) && $_GET['user'] != "" && isset($_GET['token']) && $_GET['token'] != ""){ include_once("scripts/connect.php"); $user = preg_replace('#[^0-9]#', '', $_GET['user']); $token = preg_replace('#[^a-z0-9]#i', '', $_GET['token']); $stmt = $db->prepare("SELECT user, token FROM activate WHERE user=:user AND token=:token LIMIT 1"); $stmt->bindValue(':user',$user,PDO::PARAM_INT); $stmt->bindValue(':token',$token,PDO::PARAM_STR); try{ $stmt->execute(); $count = $stmt->rowCount(); if($count > 0){ try{ $db->beginTransaction(); $updateSQL = $db->prepare("UPDATE members SET activated='1' WHERE id=:user LIMIT 1"); $updateSQL->bindValue(':user',$user,PDO::PARAM_INT); $updateSQL->execute(); $deleteSQL = $db->prepare("DELETE FROM activate WHERE user=:user AND token=:token LIMIT 1"); $deleteSQL->bindValue(':user',$user,PDO::PARAM_INT); $deleteSQL->bindValue(':token',$token,PDO::PARAM_STR); $deleteSQL->execute(); if(!file_exists("members/$user")){ mkdir("members/$user", 0755); } $db->commit(); echo 'Your account has been activated! Click the link to log in: <a href="login.php">Log In</a>'; $db = null; exit(); } catch(PDOException $e){ $db->rollBack(); echo $e->getMessage(); } }else{ echo "Sorry, There has been an error. Maybe try registering again derp."; $db = null; exit(); } } catch(PDOException $e){ echo $e->getMessage(); $db = null; exit(); } } ?> Edited June 14, 2013 by cabbie Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 14, 2013 Share Posted June 14, 2013 A lot of meaningless code as it applies to this problem. The previous poster tried to tell you something. Heed it and then get back to us with the pertinent code sample if necessary. Quote Link to comment Share on other sites More sharing options...
cabbie Posted June 14, 2013 Author Share Posted June 14, 2013 This is what I needed .. $dstfile="members/{$user}/we.png"; Quote Link to comment 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.