php-File Preview
The previous blog is the upload function, this post is uploaded picture preview and changes:
The code is as follows:
1.yulan.php
<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >#yl {width:200px; height:300px; Background-image:url (images/timg1.jpg); background-size:200px 300px;} #file{width:200px; height:300px; float:left; opacity:0;}</style>//callback function, call the method to pass a file path, change the background mapfunctionshowimg (URL) {vardiv = document.getElementById ("YL"); Div. style.backgroundimage = "url (" +url+ ")"; Document. getElementById ("TP"). Value =URL;}</script>2.ylchuli.php
<?PHPif($_files["File"] ["Error"]){ Echo $_files["File"] ["Error"];}Else{ if(($_files["File"] ["Type"]== "Image/jpeg" | |$_files["File"] ["Type"]== "Image/png") &&$_files["File"] ["Size"]<1024000) { $fname= "./images/".Date("Ymdhis").$_files["File"] ["Name"]; $filename=Iconv("UTF-8", "gb2312",$fname); if(file_exists($filename)) { Echo"<script>alert (' the file already exists! ');</script> "; } Else { Move_uploaded_file($_files["File"] ["Tmp_name"],$filename); $delurl=Iconv("UTF-8", "gb2312",$_post["TP"]); unlink($delurl);//Deleting Files Echo"<script>parent.showimg (' {$fname} ');</script> "; } }} php-file preview feature