2010-11-21 77 views
0

我試圖實現使一個很好的形式上傳的這個方法:形式上傳問題

www.kavoir.com/2009/02/styling-file-upload-select-input-control-input -typefile.html/

這是驚人的和簡單的,但我唯一的問題是,每次我選擇一個文件它顯示爲「C:\ fakepath \文件名」。我在Mac上,我不能爲我的生活弄清楚這是從哪裏來的!這是我的代碼:

<?php 
error_reporting(E_ALL^E_NOTICE); 
ini_set('display_errors', '1'); 
if ($_POST['submit'] == "Submit") { 
$temp_file = $_FILES['upload']['tmp_name']."/".$_FILES['upload']['name']; 
$target_file = getcwd()."/uploads/".$_FILES['upload']['name']; 
// if (!move_uploaded_file($temp_file,$target_file)) { 
// 
// } 
} 


?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 

<title>untitled</title> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
<style> 
    .upload { 
    position:relative; 
    width:250px; 
    height:135px; 
    border:1px solid #666; 
    padding:10px; 
    background:#DDD; 
    } 
    .loading { 
    background:rgba(50,50,50,0.8); 
    position:absolute; 
    top:0; 
    left:0; 
    width:250px; 
    height:135px; 
    } 
    .realupload { 
    position:absolute; 
    bottom:0; 
    right:0; 

    /* start of transparency styles */ 
    opacity:0; 
    -moz-opacity:0; 
    filter:alpha(opacity:0); 
    /* end of transparency styles */ 

    z-index:2; /* bring the real upload interactivity up front */ 
    width:200px; 
    } 
    form .fakeupload { 
/* background:url(uploadify/select.png) no-repeat 100% 50%; 
*/ } 
    form .fakeupload input { 
    width:238px; 
    font-family:Arial,sans-serif; 
    padding:5px; 
    border:1px solid #666; 
    background:#FFF; 
    outline:none; 
    } 
    label { 
    width:120px; 
    height:30px; 
    } 
    label img { 
    cursor:pointer; 
    } 
    .upload a.cancel { 
    position:absolute; 
    top:10px; 
    right:10px; 
    } 
</style> 
</head> 

<body> 
<div class="upload"> 
<form name="file" method="post" action="test.php" enctype="multipart/form-data"> 
<label for="realupload"><img src="uploadify/select.png" /></label> 
<div class="fakeupload"> 
    <input type="text" name="fakeupload" /> <!-- browse button is here as background --> 
</div> 
<input type="file" name="upload" id="realupload" class="realupload" onchange="this.form.fakeupload.value = this.value;" /> 
<input id="submit" type="submit" name="submit" value="Submit" /> 
</form> 
<a class="cancel" href="test.php"><img src="uploadify/cancel.png" /></a> 
<div class="loading"></div> 
</div> 
<script> 
$(document).ready(function() { 
    $('div.loading').fadeOut(0); 
}); 
$('form input.submit').click(function() { 
    $('div.loading').fadeIn(400); 
}); 
</script> 
</body> 
</html> 

回答

1

這是瀏覽器的安全級別。我在Windows(IE)上遇到過這個問題,但令人驚訝的是,你在Mac上。嘗試其他瀏覽器或更改當前瀏覽器的安全選項。使它不太保守。

此外,請嘗試使用其他網站的上傳表單。

+0

我在Chrome中得到這個,但是我只是在Firefox中獲取文件名。很奇怪。瀏覽器組成了它自己的目錄(「fakepath」必須以某種方式基於我的代碼)? – 2010-11-21 01:58:19

+0

同樣的路徑也出現在從該頁面鏈接的例子中。很奇怪! – 2010-11-21 01:59:20