Simple Upload Form Question

Discussion in 'PHP' started by crath, Nov 17, 2008.

  1. #1
    well I don't see anything wrong in the code, but im probably looking right over the problem. here is the upload function.

    	function upload(){
    	echo "step1<br/>";
    	$path = "img/" . $_GET['id'] . '/' .rand(11,99). $HTTP_POST_FILES['ufile']['name'];
    	if($ufile != none){
    		echo "step2<br/>";
    		if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)){
    			echo "step3<br/>";
    			chmod($path, 0777);
    		}
    	} else {
    		echo'<span style="color:red">Upload Failed</span><br/>';
    	}
    }
    PHP:
    and it is returning step1 and step2, but not step3 so something somewhere is going wrong.

    before i completely re-write this, does any of you see a problem? thanks!
     
    crath, Nov 17, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    can you post the form?

    -> $HTTP_POST_FILES['ufile']['name']
    -> $_GET['id']

    are these existing? make sure you pass this globaly into the function.. i dont see any parameters in your function
     
    bartolay13, Nov 17, 2008 IP
  3. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #3
    <form method='post' action='?act=modify&id=$id' enctype='multipart/form-data'>Add Image <input type="file" name="ufile"/><input type="submit" value="Upload" name="upload"/></form>
    PHP:
    and the id variable is always set, and i made sure it was being put into the form action correctly which it was.
     
    crath, Nov 18, 2008 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Cant find the error but
    regarding this part :
    $ufile is? Did u assign a value to it? I see its a function and there isn't anything assignation regarding $ufile

    
    $ufile = $HTTP_POST_FILES['ufile']['name']; // maybe
    if($ufile != ''){
    
    PHP:
    Anyway this is not the problem as it prints out step2

    Try rename instead of copy.
     
    ads2help, Nov 18, 2008 IP
    crath likes this.