Adebayo Ojo
asked on
Issue with copying file between sub directories in PHP
I have a PHP script, signup.php inside this directory: /var/www/html/signup.php
Inside this signup.php file, I have the below lines of code to copy file between sub-directories:
Please what could be my mistake?
Inside this signup.php file, I have the below lines of code to copy file between sub-directories:
$avatar = "images/avatardefault.png";
$avatar2 = "var/www/html/user/avatardefault.png";
if (!copy($avatar, $avatar2)) {
echo "failed to create avatar.";
}
But when I run this script, I get an error:PHP Warning: copy(var/www/html/user/avatardefault.png): failed to open stream: No such file or directory in /var/www/html/signup.php
Please what could be my mistake?
This line:
$avatar2 = "var/www/html/user/avatard efault.png ";
...probably needs an initial slash:
$avatar2 = "/var/www/html/user/avatarde fault.png" ;
Otherwise, it is taking your CURRENT folder, /var/www/html/, and then looking for that path INSIDE of it, like this:
/var/www/html/var/www/html /user/avat ardefault. png
$avatar2 = "var/www/html/user/avatard
...probably needs an initial slash:
$avatar2 = "/var/www/html/user/avatarde
Otherwise, it is taking your CURRENT folder, /var/www/html/, and then looking for that path INSIDE of it, like this:
/var/www/html/var/www/html
@Adebayo,
Do you still require assistance with this question? If so post back here, otherwise please can you close the question.
Do you still require assistance with this question? If so post back here, otherwise please can you close the question.
ASKER
This issue has to do with the owner and permission of that file "signup.php"
I was able to copy once the owner and permission was corrected.
Thanks. Yes you can close the question.
I was able to copy once the owner and permission was corrected.
Thanks. Yes you can close the question.
That doesn't make sense. The error message has nothing to do with permissions / ownership. If it were a permissions issues, you'd get an error related to permissions being denied (and the code would not have been able to be executed), and the code you showed definitely had the relative path issue. Are you certain you didn't have multiple problems that all contributed to the issue?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
Check in the var/www/html folder to see if there isa) A folder called user
b) It is all lower case (on Unix systems User != user