SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Locally testing my file uploading code

    I was wondering whether or not its possible to locally test the code that would upload files to a certain directory on my server if done remotely.

    The code at the moment works a dream on my web server but I can't get it to work locally for whatever reason.
    Code:
    $path_to_file = $HTTP_SERVER_VARS['DOCUMENT_ROOT']."/images/";
    $i = 1;
    foreach ($_FILES['files']['name'] as $key=>$name) 
    {
    	$FILENAME[$i] = $_FILES[files][name][$key];
    				
    	IF($_FILES['files']['name'][$key])
    	{		
    		
    		IF(file_exists($path_to_file . $_FILES['files']['name'][$key]))
    		{ 
    			echo "$FILENAME could not be uploaded because a file with the same name already exists.<br>";					 
    		}		
    				
    			ELSEIF(!is_uploaded_file($_FILES['files']['tmp_name'][$key]))
    			{ 
    				IF($_FILES['files']['size'][$key] > $_POST[MAX_FILE_SIZE])
    				{
    					echo "$FILENAME could not be uploaded because its file size was bigger than the allowed 140kb.<br>";
    				}
    			} 
    	
    				ELSE
    				{
    					$current_size = getimagesize($_FILES['files']['tmp_name'][$key]);
    					$current_img_width[$i] = $current_size[0];
    					$current_img_height[$i] = $current_size[1];
    					
    					/* IF ITS A GIF OR JPEG PROCESS */
    					IF($size[2] == 1 || $size[2] || 2)
    					{
    						IF(move_uploaded_file($_FILES['files']['tmp_name'][$key], $path_to_file . $FILENAME)) 
    						{		
    							echo "$FILENAME was successfully uploaded.";
    						}
    					}
    																					
    						ELSE
    						{
    							echo "$FILENAME could not be uploaded because its file type is not authorized.<br>";											
    						}
    				}																	  
    	}
    							
    	$i++;
    }
    Would appreciate it if anyone could point out any changes I must make in order to make the code locally compatible.
    Bardius

  2. #2
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code is so much easier to read when its not compressed into a blob.

    PHP Code:
    $path_to_file $HTTP_SERVER_VARS['DOCUMENT_ROOT']."/images/"
    $i 1

    foreach (
    $_FILES['files']['name'] as $key => $name) { 
        
    $FILENAME[$i] = $_FILES['files']['name'][$key]; 
        if(
    $_FILES['files']['name'][$key]) { 
            if(
    file_exists($path_to_file $_FILES['files']['name'][$key])) { 
                echo 
    $FILENAME[$i] . " could not be uploaded because a file with the same name already exists.<br>"
            } elseif(!
    is_uploaded_file($_FILES['files']['tmp_name'][$key])) { 
                if(
    $_FILES['files']['size'][$key] > $_POST['MAX_FILE_SIZE']) { 
                    echo 
    $FILENAME[$i] . " could not be uploaded because its file size was bigger than the allowed 140kb.<br>"
                } 
            } else { 
                
    $current_size getimagesize($_FILES['files']['tmp_name'][$key]); 
                
    $current_img_width[$i] = $current_size[0]; 
                
    $current_img_height[$i] = $current_size[1]; 
                
    /* IF ITS A GIF OR JPEG PROCESS */ 
                
    if($size[2] == || $size[2] || 2) { 
                    if(
    move_uploaded_file($_FILES['files']['tmp_name'][$key], $path_to_file $FILENAME[$i])) { 
                        echo 
    $FILENAME[$i] . " was successfully uploaded."
                    } 
                } else {     
                    echo 
    $FILENAME[$i] . " could not be uploaded because its file type is not authorized.<br>"
                } 
            } 
        } 
        
    $i++; 

    Dunno if that'll work for you...


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
  •