Page 1 of 1

copy and paste file...solved

Posted: Sat Sep 05, 2009 8:43 pm
by scarface222
Hey guys I just want to copy and paste a picture but my function is not working, the page just executes without doing anything. no error messages or anything. Any ideas would really help me. Thanks.

Code: Select all

$src='../../images';
         $dest='../../usercontent/$username/images';
         $fsrc = fopen($src,'r');
        $fdest = fopen($dest,'w+');
         $file = '../../images/defaulticon.png';
      $newfile = '../../usercontent/$username/images/defaulticon.png';
     copy($file, $newfile);
     fclose($fsrc);
       fclose($fdest);
         header("Location: ".$session->referrer);

Re: copy and paste file... help appreciated

Posted: Sat Sep 05, 2009 9:03 pm
by scarface222
Thanks for the response but still no luck man. I changed it and all the code right up to and after the copy fucntion executes.

Code: Select all

$_SESSION['reguname'] = $_POST['user'];
         $username=$_POST['user'];
         $_SESSION['regsuccess'] = true;
         mkdir("../usercontent/$username",0777);
         mkdir("../usercontent/$username/images",0777);
         //copy default pic
         $file = '../../images/defaulticon.png';
      $newfile = "../../usercontent/$username/images/defaulticon.png";
     copy($file, $newfile);
         header("Location: ".$session->referrer);

Re: copy and paste file... help appreciated

Posted: Sun Sep 06, 2009 4:32 am
by Mark Baker
Are you sure that your paths are right:

Code: Select all

mkdir("../usercontent/$username/images",0777);
and

Code: Select all

$newfile = "../../usercontent/$username/images/defaulticon.png";
don't seem correct to me: too many ../

You're creating a new directory, but trying to copy the file to a location that's nowhere near that new directory.

Re: copy and paste file... solved

Posted: Sun Sep 06, 2009 11:06 am
by scarface222
LOL thanks man you got some good eyes and that was a dumb mistake. You were exactly right. Appreciate the comments.