Mr.Canuck Posted October 9, 2010 Share Posted October 9, 2010 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 https://forums.phpfreaks.com/topic/215500-point-images-to-upload-to-different-directory/ Share on other sites More sharing options...
BlueSkyIS Posted October 9, 2010 Share Posted October 9, 2010 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 https://forums.phpfreaks.com/topic/215500-point-images-to-upload-to-different-directory/#findComment-1120600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.