Jump to content

Point images to upload to different directory


Mr.Canuck

Recommended Posts

I have a PHP script that uploads images to a folder on my server  (attachments folder). Currently the folder sits within my webroot and is publicly accessible (I have to use chmod 777 due to permissions issue). So, I created the "attachments" folder outside of my webroot (so that it is not publicly accessible), but I do not know how to set the path in the PHP code to upload it to that "attachments" folder outside of the webroot. As you see in the snippet of PHP code below, the code currently uploads the the "attachments" folder within the www (webroot) directory. How do I make it upload to the "attachments" folder OUTSIDE of the www (webroot) directory?

 

foreach($files[$form] as $file){
         $str = $file[1];
         if (eval("if($str){return true;}")) {
            $_values[$file[0]] = $_FILES[$file[0]]["name"];
            $dirs = explode("/","attachments//");
            $cur_dir =".";
            foreach($dirs as $dir){
            $cur_dir = $cur_dir."/".$dir;
            if (!@opendir($cur_dir)) { mkdir($cur_dir, 0777);}}
            $_values[$file[0]."_real-name"] = "attachments/".date("YmdHis")."_".$_FILES[$file[0]]["name"]."_secure";
            copy($_FILES[$file[0]]["tmp_name"],$_values[$file[0]."_real-name"]);
            @unlink($_FILES[$file[0]]["tmp_name"]);
         }else{
          $flag=true;
          if ($_isdisplay) {
              //$ExtFltr = $file[2];
              //$FileSize = $file[4];
            if (!eval("if($file[2]){return true;}")){echo $file[3];}
            if (!eval("if($file[4]){return true;}")){echo $file[5];}
              $_ErrorList[] = $file[0];
          }
         }
      }

 

Thanks

Link to comment
Share on other sites

How do I make it upload to the "attachments" folder OUTSIDE of the www (webroot) directory?

 

 

Use the full path to the directory instead of a relative path, usually something like /usr/yourdomainroot/attachments/ where the document_root is in /usr/yourdomainroot/html/

 

Note: Some PHP and/or server set-ups will not allow you to write to a directory outside of $_SERVER['DOCUMENT_ROOT']

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.