php無重新整理利用iframe實現頁面無重新整理上傳檔案(1/2)_PHP教程

來源:互聯網
上載者:User
利用form表單的target屬性和iframe

一、上傳檔案的一個php教程方法。
該方法接受一個$file參數,該參數為從用戶端擷取的$_files變數,返回重新命名後的檔案名稱,如果上傳失敗,則返回Null 字元串。
php代碼

function uploadfile($file) {
// 上傳路徑 $destinationpath = "./upload/";
if (!file_exists($destinationpath)){
mkdir($destinationpath , 0777); }
//重新命名
$filename = date('ymdhis') . '_' . iconv('utf-8' , 'gb2312' , basename($file['name']));
if (move_uploaded_file($file['tmp_name'], $destinationpath . $filename)) { return iconv('gb2312' , 'utf-8' , $filename);
} return '';
}

二、用戶端html代碼
這裡正是技巧所在,添加另一個iframe來實現。表單標籤form定義了一個屬性target,該屬性解釋如下:
[pre]target屬性:
_blank ---------- 新開視窗
_self ----------- 自身
_top ------------ 主架構
_parent --------- 父架構
自訂名字 ----- 出現於架構結構,將會在該名稱的架構內開啟連結

本例中採用iframe名字,所以表單在提交時會在iframe內開啟連結(即無重新整理,確切的說應該是
感覺無重新整理)
在表單提交時,調用startupload方法,當然這是js定義的。
[/pre][pre]此外我們還定義一個span來顯示提示資訊。代碼如下:
[/pre]xhtml代碼

匯入檔案:
iframe><br /> form> <span id="info">span> </blockquote><p>1 2 <br></p><p align="left"><span id="url" itemprop="url">http://www.bkjia.com/PHPjc/444809.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/444809.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">利用form表單的target屬性和iframe 一、上傳檔案的一個php教程方法。 該方法接受一個$file參數,該參數為從用戶端擷取的$_files變數,返回重新...</span></p><li ><i class="layui-icon">&#xe63a;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.