webent Posted June 25, 2008 Share Posted June 25, 2008 Hi all, I am trying to copy images from one directory on one domain to another directory on another domain, but I get permission denied... I have both directory's permissions set to 777, so I assume it's a chown thing, would that be correct? Here's my code... if (isset($_GET['CATEGORY'])) { $result = mysql_query("SELECT SKU, PRODUCT_IMAGE, MSRP, PRODUCT_NAME FROM $_GET[PRODUCT_LINE] WHERE CATEGORY = '$_GET[CATEGORY]' LIMIT 10"); while ($row = mysql_fetch_assoc($result)) { $image = retrieveImage($row[PRODUCT_IMAGE]); echo '<img src="' . $image . '" />'; echo '<br>' . $row[PRODUCT_NAME] . ' - $' . $row[MSRP] . '<br>'; } exit; } function retrieveImage($image) { $image = "/home/mainaccount/public_html/supplier/images/$image"; $new_destination = "images/$image"; copy($image, $new_destination); return; } Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/ Share on other sites More sharing options...
trq Posted June 25, 2008 Share Posted June 25, 2008 What are the persmissions on the files you are trying to copy? Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574518 Share on other sites More sharing options...
webent Posted June 25, 2008 Author Share Posted June 25, 2008 644 , that would be my problem then wouldn't it... having some issues with chmod sticking though... I went and re-checked the permissions on the directory that I told you was 777, it was back to 755 ... perhaps I have to ssh in as root and do it, for it to stick, perhaps a Cpanel security issue or something that won't allow non-root users to change permissions... On that subject, I'll have to find the unix command for chmod all the contents in a directory ... I assumed that when you chmod a directory, all contents changed to that value... Unless that goes back to what I originally was saying about how the chmod isn't taking... Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574531 Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 A directory can't really be 777 because you can't execute a directory, which is what that last bit stands for. So 755 is how most directories are set. Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574541 Share on other sites More sharing options...
webent Posted June 26, 2008 Author Share Posted June 26, 2008 Gotcha, good info, thank you... When I chmod that directory though, shouldn't it of changed the attributes for all the images within as well? Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574548 Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 No, you need to run chmod with the recursive flag. Not sure if you can do that on your FTP client. On the shell it would be: chmod -R 755 path/to/directory Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574550 Share on other sites More sharing options...
webent Posted June 26, 2008 Author Share Posted June 26, 2008 I just tried that, but it didn't change the permissions of the images within the directory, did it from root via ssh... Do you think that it is because my root privileges are in a vps and not a true dedicated, that my abilities to do such functions are limited? Edit: Did it again, using the full path instead of just being in the next up directory and naming the directory... It worked! Buh Yah! Now let's just see if the Copy() works... Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574561 Share on other sites More sharing options...
poelinca Posted June 26, 2008 Share Posted June 26, 2008 chmod("filename", 0444) , worked for me all the times on different hosts ( mainly using this for log files and it never failed ) you should run it inside php file like this if ( chmod("filename", 0444) ) { //do stuff here } else { //error stuff here } Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574583 Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 @poelinca: You usually always want a 7 in the second position of the octal, not a 4. Because 4 is "execute", so 444 means that everyone can execute it but can't read or write it. Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574585 Share on other sites More sharing options...
poelinca Posted June 26, 2008 Share Posted June 26, 2008 oki then 7 it is , never whent to deep into this , let me check back , it should be "0660" "rw-rw----" , read write for owner and group , or "0760" "rwxrw----"for read write execute for owner and read write for group . back once more and gues what 4 is for read hahaha , so my log files never neded 0444 , but 0660 Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574586 Share on other sites More sharing options...
webent Posted June 26, 2008 Author Share Posted June 26, 2008 Actually what I think happened when I first tried to change the permissions like DarkWater instructed me to, I didn't wait long enough... I think it took a while to change permissions for 30,000 images... copy() still does not work, still gives "Permission denied", even changed both directories and all images to 777 Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574594 Share on other sites More sharing options...
webent Posted June 26, 2008 Author Share Posted June 26, 2008 I just changed chown of the image folder and all of it's files to the same owner of the domain that is calling the copy(), still "Permission denied" This just does not make since... Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574614 Share on other sites More sharing options...
webent Posted June 26, 2008 Author Share Posted June 26, 2008 Tried a completely different route and it doesn't do anything at all... function retrieveImage($image) { $old_destination = "/home/mainaccount/public_html/supplier/images/$image"; $new_destination = "images/$image"; //copy($old_destination, $new_destination); exec("cp -R $old_destination $new_destination"); return; } Quote Link to comment https://forums.phpfreaks.com/topic/111934-solved-copy-permission-denied/#findComment-574647 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.