简体   繁体   中英

I am trying to move a file from one path to another in PHP without success

I am trying to move a file 'avatars/generic.jpg' to a folder that has a dynamic variable in it - $_SESSION['user_id'] - the path would look like this

avatars/$_SESSION['user_id']/generic.jpg 

but I can't get it to work using the copy function in PHP. I have tried curly braces etc around the session variable without success....

Any suggestions?

Try:

<?php
    copy("avatars/generic.jpg", "avatars/" . $_SESSION['user_id'] . "/generic.jpg"); 
?>

By using the '.' operator for concatenation you don't have to worry about escaping.

kindly use . as to concatinate the variables

"...avatars/".$_SESSION['user_id']."/generic.jpg ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM