SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Move Image to Secure Folder

    Hi,

    I am wondering how to move a image to a secure folder after it has been uploaded to a 777 folder?

    Below is the code I use to copy the image to "pictures" folder. What I like to do is move it to say pictures2 folder which would be 755

    PHP Code:
    copy($jpgimage"/home/something/public_html/pictures/$jpgimage_name); 

  2. #2
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    copy('/home/something/public_html/pictures/' $jpgimage_name'/home/some/safe/folder/' $jpgimage_name); 
    - website

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get this error

    Warning: copy(/home/something/public_html/pictures/Copy of avonlee1.jpg) [function.copy]: failed to create stream: No such file or directory in /home/something/public_html/admin/picturesadd.php on line 42

  4. #4
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well if you do
    PHP Code:
    copy($jpgimage'/home/something/public_html/pictures/' $jpgimage_name);
    copy('/home/something/public_html/pictures/' $jpgimage_name'/home/some/safe/folder/' $jpgimage_name); 
    Assuming that $jpgimage is fullpath to the temp image, then you move it to /home/something/public_html/pictures/ folder and then you simply copy it to some another folder.

    Could you post your current code please ?
    - website

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code works fine if I don't have to move the file
    PHP Code:
    <?
    if (!$submit)
    {
    ?>
    <table cellspacing="5" cellpadding="5">
    <form action="<? echo $PHP_SELF?>" enctype="multipart/form-data" method="POST">
    <tr>
    <td valign="top"><font size="-1">Headline (Just One Word About Picture)</font></td>
    <td><input size="50" maxlength="250" type="text" name="head"></td>
    </tr>
    <tr>
    <td valign="top"><font size="-1">Description</font></td>
    <td><textarea name="descrip" cols="40" rows="10"></textarea></td>
    </tr>
    <tr>
    <td colspan=2>Enter file name JPG <input name="jpgimage" type="file"></td>
    </tr>
    <input type="hidden" name="MAX_FILE_SIZE" value="50000000">
    <tr>
    <td colspan=2><input type="Submit" name="submit" value="Add"></td>
    </tr>
    </form>
    </table>
    <?
    }else{
            
     include(
    "../conf.php");
     include(
    "../functions.php");
            
    copy($jpgimage'/home/something/public_html/pictures/' $jpgimage_name);
            
    copy('/home/something/public_html/pictures/' $jpgimage_name'/home/something/public_html/pictures2/' 
    $jpgimage_name);

  6. #6
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see...

    replace
    PHP Code:
            copy($jpgimage'/home/something/public_html/pictures/' $jpgimage_name);
            
    copy('/home/something/public_html/pictures/' $jpgimage_name'/home/something/public_html/pictures2/' 
    $jpgimage_name); 
    with
    PHP Code:
            move_uploaded_file($_FILES['jpgimage']['tmp_name'], '/home/something/public_html/pictures/' $_FILES['jpgimage']['name']);
            
    copy('/home/something/public_html/pictures/' $_FILES['jpgimage']['name'], '/home/something/public_html/pictures2/' $_FILES['jpgimage']['name']); 
    check out http://www.php.net/manual/en/features.file-upload.php

    the $_FILES array should be used instead of the old _name etc.
    - website

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it uploaded fine to pictures folder but wouldn't move to pictures2
    got an [function.copy]: failed to create stream: Permission denied

    I think what I'll end up doing is just chmod the file after it's uploaded and keep it in the pictures folder

  8. #8
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    very wise decision I think, pointless to keep it on 2 places...
    - website


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
  •