0

hi i can easily upload image in php as follows code

            @$file_path = "admin/alumni_image/";
            @$file_name=  basename($_FILES['photo']['name']);

            @$file_path = $file_path . basename( $_FILES['photo']['name']);
            if(move_uploaded_file(@$_FILES['photo']['tmp_name'], $file_path)) 
            {
                $response1=array();

                $query = "update alumni set photo = '".$file_name."' where alumni_id = '".$data['alumni_id']."'";
                $query_run=  mysql_query($query);
                echo mysql_error();


             } 

but now i facing problem when doing same when i got image as base64.

3
  • 3
    What is about those @ that this code seems to love so much? Commented Aug 20, 2014 at 9:13
  • @ for no error shown if not used Commented Aug 20, 2014 at 9:15
  • Is the question, what to do with it after uploading? Since uploading is uploading, whether it's base64 encoded or not? Commented Aug 20, 2014 at 9:15

1 Answer 1

2

Recently I've built something like that:

        define("UPLOAD_DIR", "images/signatures/");
        $signature = $_POST['signature']; // THIS IS YOUR BASE64 ENCODED STRING
        $signature = str_replace('data:image/png;base64,', '', $signature);
        $signature = str_replace(' ', '+', $signature);
        $data = base64_decode($signature);
        $file = UPLOAD_DIR . md5(microtime()) . '.png';
        $success = file_put_contents($file, $data);
Sign up to request clarification or add additional context in comments.

4 Comments

okk can u also provide how to encode image in base 64 so that i can test it on my side
here used microtime() and encode with md5.either there is a condition when two image have same name
no image will have the same name when md5(microtime).
i use same code for uploading image but when i use same code for multiple image both image with .png extention i found in the folder but second upload image not found ............

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.