upload file inside a form html

后端 未结 4 1766
感动是毒
感动是毒 2020-12-22 00:45

I want to create a form to submit a product which has a features to upload images inside the form.

my difficulties are :

  1. I find it hard to upload file
4条回答
  •  醉梦人生
    2020-12-22 01:27

    When working with uploading data,say, image. you should add the enctype form as others suggested.

    .............

    Here's the uploader script of Javascript as follows:

    
    
    
    
    

    Place the scriptabove wherever you wish,e.g. above submit button.

    UPDATED: Codes to upload image in PHP (for ex.):

    $uploadpath='../usrphoto/'; //image path 
    $allowtype=array('gif','jpg','png');
    $allowsize=71250;
    
    
    if(isset($_FILES['file']) && strlen($_FILES['file']['name']) > 1){
                $uploadpath=$uploadpath . basename( $_FILES['file']['name']);
                $sepext=explode('.', strtolower($_FILES['file']['name']));
                $type=end($sepext); 
                if(!in_array($type, $allowtype)){
                    echo "";
                    header("Location: http://www.mywebsite.com/");
                    }
                elseif ($allowsize>71250){
                    echo "";
                    header("Location: http://www.mywebsite.com/");
                    }
                else{
                    if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadpath)){ 
                        echo 'successfully uploaded!';
                    else{
                        header("Location: http://www.mywebsite.com/");
                        }
                    }
                }
    

提交回复
热议问题