PHP function for uploading files error

Discussion in 'PHP' started by pcf43, Nov 9, 2010.

  1. #1
    I am doing a site, and I made a form in html, than made an upload function for avatars which after that I want the file to be shown in a preview in the browser near the upload form. I did the function in php on another file and linked it to the respective upload form, problem is the server is getting me an error on line 7 which is actually the $goto1 variable, any ideea why is this happening? Here is the code to both, html upload form and php function:
    HTML Code:
    <form action="avatar_upload.php" method="post">						<!--Avatar upload form-->
    Upload avatar:<input type="file" name="avatar_upload" />
    <input type="submit" value="Upload avatar" name="avatarUploadaSubmit"><br/>
    <div class="font-style-desc">
    Avatar upload image. Please pick a avatar upload image. Image<br/> 
    type must be JPEG or PNG only, must not be larger than 500KB <br/>
     and has to be no larger than 136 in width and 164 in height. 
    </div class="font-style-desc">
    	<form name="avatarImage" action="avatar_upload.php">							<!--Synched avatar image-->
    	<input type="image" action="avatar_upload.php">
    	
    </form>
    HTML:
    PHP code:
    <?php
    
    function moveToDir(){													//function to move uploaded images to chosen folder in $destination variable and to upload the file itself
    $uploadedFile=$_FILES["avatar_upload"];
    $destination='/images/avatars';
    $avatarUploadSubmit=$_["avatarUploadaSubmit"];
    $goto1=bool move_uploaded_file(string $uploadedFile, string $destination);
    
    	if($avatarUploadSubmit==true){
    		echo $goto1;
    
    			}
    }
    
    else function moveToDir( > 0){
    
    echo "Error, could not upload file: " .$uploadedFile["error"]. "<br/>"}
    
    else{
    echo "Uploaded: ".$uploadedFile["name"];
    
    } 
    ?>
    PHP:

     
    pcf43, Nov 9, 2010 IP
  2. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    remove the word "string" from the goto line.
     
    bencummins, Nov 9, 2010 IP
  3. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    looks like lots of bug in code.
    You need clean code for uploading the file to server.
     
    xpertdev, Nov 10, 2010 IP
  4. jam4517549

    jam4517549 Member

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    don't forget to add enctype="multipart/form-data" if your dealing w/ files ..
     
    jam4517549, Nov 10, 2010 IP