SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: copy() problem

  1. #1
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    copy() problem

    Hi there...

    I have the following problem...

    during a registration process(which has to be confirmed via email) the user can upload his company logo and one other file...

    Until the registration is confirmed via email I keep the files in a
    /data/temp/ directory....

    when user confirms his registration via email the logo is copied
    from /data/temp/ to

    /data/company_id/

    and this other file is copied to
    /data/company_id/user_id/

    after copying, the files are deleted from /temp/

    The problem is that the dynamic created directories and copied files cannot be deleted manualy from the server!???I tried via SmartFTP and directly from cPanel but nothing...Also the logo isn't copied to /company_id/ dir and if I try to upload it manualy I can't because I have no permission...

    Then I contacted my support and they deleted the files but that isn't solution...

    I tried google but couldn't find nothing useful about this...

    Any help would be appriciated cause I don't know what to do..

    the code itself is just plain

    copy($source, $destination);
    unlink($source);

    where $destination is a full file name not just a directory which was suggested in the php manual....

    UPDATE: I just noticed that only the logo isn't copied!?this other file is copied to user_id directory but the logo isn't to parent directory...

    however I cannot delete the user_id directory nor any files in it...

    I hope I made this clear...
    exit(0);

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is most certainly a permissions problem...php runs as its own user, and not as you, so anything that php does you usually can't undo unless you happen to be in the same group as php or if the file/directory happens to be world-writeable

    to solve your problems, here are a few solutions:

    1) for the logo problem, make sure that /data/company_id/ is writeable by whatever user php runs as (usually means that the folder has to be world-writeable)...i'm guessing that you just made the /data/company_id/ directory by yourself, and it is probably set with permissions at 775 or 755, which means that php can't write to it

    2) the other file is being uploaded properly because php is creating the directory that it is being uploaded to, so php obviously has the permissions to create files in that directory

    3) to be able to delete manually the files that php uploads, make use of the chmod() function:
    PHP Code:
    chmod($file0777);
    // or
    chmod($dir0777); 
    that will set the file to be world-writeable, so later on you can do whatever you want with it

    the dangers of world-writeable is that it can be a large security hole if the files are stored in a folder beneath the server root...the best thing to do might be to upload the files to a directory above the server root (if you have the ability to do so), and then simply make a soft link beneath the root back to that file, ie:
    /home/web/ is the folder that translates to www.example.com
    store the files in /webfiles so that it is not accessible through the web
    make a soft link (through php with symlink()) in /home/web/data/company_id/ so that the file can be seen (but not modified) over the web

    sorry for the length...hopefully this made sense!

  3. #3
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi and really thanx for the answer....

    Hm the directories are created with mkdir($name, 0777) so the directory has the 0777 permission but I read some user inputs on php.net under mkdir() function..

    I found this:

    You might notice that when you create a new directory using this code:

    mkdir($dir, 0777);

    The created folder actually has permissions of 0755, instead of the specified
    0777. Why is this you ask? Because of umask(): http://www.php.net/umask

    The default value of umask, at least on my setup, is 18. Which is 22 octal, or
    0022. This means that when you use mkdir() to CHMOD the created folder to 0777,
    PHP takes 0777 and substracts the current value of umask, in our case 0022, so
    the result is 0755 - which is not what you wanted, probably.

    The "fix" for this is simple, include this line:

    $old_umask = umask(0);

    Right before creating a folder with mkdir() to have the actual value you put be
    used as the CHMOD. If you would like to return umask to its original value when
    you're done, use this:

    umask($old_umask);

    but to make things worse my server is unavailable at the moment so I'll have to wait to test this all....

    Thanx again for you reply...
    exit(0);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •