How to display an image $_FILE on PHP -
i have code here handles upload of images.
however reason $file_destination variable unrecognize outsizde ifs statements. want attain output $file_destination variable inside tag. when use variable wont work outside.
//file uploading codes (need inside function) global $file_destination; if(isset($_files['file'])){ $file = $_files['file']; print_r($file); // file properties $file_name = $file['name']; $file_tmp = $file['tmp_name']; $file_size = $file['size']; $file_error = $file['error']; //file extension $file_ext = explode('.', $file_name); $file_ext = strtolower(end($file_ext)); //check file type allowed $allowed = array('png', 'jpg'); if(in_array($file_ext, $allowed)){ if($file_error === 0){ if($file_size <= 2097152){ $file_name_new = uniqid('', true). '.'.$file_ext; $file_destination = 'c:/'.$file_name_new; if(move_uploaded_file($file_tmp, $file_destination)){ echo $file_destination; } } } } } echo <img src="<?php $file_destination ?>"> it wont work since $file_destination doesnt recognize. idea?
maybe problem security of browser. browser dont let show localfiles hd: c:/myimages.jpg
try point "src" resource (image file) in web server:
example: <img src="http://localhost/myimages.jpg">
Comments
Post a Comment