Don E Posted January 18, 2013 Share Posted January 18, 2013 Hello everyone, Does the copy function only take literal strings for parameters, and not variables that are strings? is there a way to copy a file where the path and name are stored in a variable?http://php.net/manual/en/function.copy.php Thanks. Link to comment Share on other sites More sharing options...
jeffman Posted January 18, 2013 Share Posted January 18, 2013 Example 1 shows copy being used with variables. So, yes. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 18, 2013 Share Posted January 18, 2013 For all intents and purposes there is no difference between a literal value and a variable holding the value (unless you're in a situation that requires a variable, like passing by reference). Link to comment Share on other sites More sharing options...
Don E Posted January 18, 2013 Author Share Posted January 18, 2013 I meant more along the lines of the following example. $origImg = "uploads/$this->pic_name";$copyImg = "uploads/$this->pic_name" . "orig";copy($origImg, $copyImg);When using the above without quotes I thought why the copy failed but doing the above with double quotes fails as well. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 18, 2013 Share Posted January 18, 2013 Do one of these: $origImg = "uploads/" . $this->pic_name; $origImg = "uploads/{$this->pic_name}"; Link to comment Share on other sites More sharing options...
jeffman Posted January 18, 2013 Share Posted January 18, 2013 Echo the value of those strings to be sure they are what you think. Then make sure the relative paths are correct. Then make sure the write permissions in the directory are correct. Link to comment Share on other sites More sharing options...
jeffman Posted January 18, 2013 Share Posted January 18, 2013 I wondered about interpolating the object element inside the quotes, too, but FWIW, this works for me: $o->file = "file";echo "str/$o->file"; Link to comment Share on other sites More sharing options...
Don E Posted January 19, 2013 Author Share Posted January 19, 2013 (edited) Thanks for the input guys. Unfortunately the following examples didn't work either: $origImg = "uploads/" . $this->pic_name;$origImg = "uploads/{$this->pic_name}"; I echoed out the variables to see if they contain the proper values and they do as well. I even tried to cast them to strings like the following and still get fail on copy: $imgToCopy = (string)"uploads/$this->pic_name";$setAsOrig = (string)"uploads/$this->pic_name" . ".orig"; It works though when setting the variables like the following: $imgToCopy = "uploads/sfsGDFDmyimage.jpg";$setAsOrig = "uploads/sfsGDFDmyimage.jpg" . ".orig"; Edited January 19, 2013 by Don E Link to comment Share on other sites More sharing options...
jeffman Posted January 19, 2013 Share Posted January 19, 2013 You might try trim() on the strings, in case they contain non-printing characters or newlines at the end. Before you do that, maybe try strlen() to see if the lengths match. Link to comment Share on other sites More sharing options...
Don E Posted January 20, 2013 Author Share Posted January 20, 2013 I managed to figure out what the problem was. There was an issue with the upload. Thanks everyone for their input.Nice to see DD around again! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now