Image upload path setting
I'm trying to add an image upload script to my site and I don't think it has configured it correctly in my directories.
The directory I'm trying to download: images/gallery/
      
        
        
        
      
    
The directory where my code is located: scripts/php/imageUpload.php
      
        
        
        
      
    
And php code in imageUpload.php
      
        
        
        
      
    :
<?php
$output_dir = "../images/gallery/";
if(isset($_FILES["myfile"]))
{
    $ret = array();
    $error =$_FILES["myfile"]["error"];
   {
        if(!is_array($_FILES["myfile"]['name'])) //single file
        {
            $RandomNum   = time();
            $ImageName      = str_replace(' ','-',strtolower($_FILES['myfile']['name']));
            $ImageType      = $_FILES['myfile']['type']; //"image/png", image/jpeg etc.
            $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
            $ImageExt       = str_replace('.','',$ImageExt);
            $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
            $NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
            move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $NewImageName);
             //echo "<br> Error: ".$_FILES["myfile"]["error"];
                 $ret[$fileName]= $output_dir.$NewImageName;
        }
        else
        {
            $fileCount = count($_FILES["myfile"]['name']);
            for($i=0; $i < $fileCount; $i++)
            {
                $RandomNum   = time();
                $ImageName      = str_replace(' ','-',strtolower($_FILES['myfile']['name'][$i]));
                $ImageType      = $_FILES['myfile']['type'][$i]; //"image/png", image/jpeg etc.
                $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
                $ImageExt       = str_replace('.','',$ImageExt);
                $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
                $NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
                $ret[$NewImageName]= $output_dir.$NewImageName;
                move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$NewImageName );
            }
        }
    }
    echo json_encode($ret);
}
?>
      
        
        
        
      
    
I tried to change directory from ../images/gallery/
      
        
        
        
      
    to /images/gallery/
      
        
        
        
      
    and toimages/gallery/
      
        
        
        
      
    
Thanks in advance.
+3 
Jesse elser 
source
to share
      
1 answer
      
        
        
        
      
    
if you are using wamp on windows operating system try this
$output_dir = $_SERVER['DOCUMENT_ROOT'] . "images/gallery/";
      
        
        
        
      
    
      try it
$output_dir = dirname(__FILE__)."/../images/gallery/";
      
        
        
        
      
     
0 
Talal farhat 
source
to share