問題描述
我正在嘗試讓 PHP 將上傳的文件從 tmp 目錄移動到我的網(wǎng)絡(luò)服務(wù)器上的某個永久位置.看起來很簡單,但我收到了這個錯誤:
I'm trying to get PHP to move an uploaded file from the tmp directory to somewhere permanent on my webserver. It seems simple enough, but I'm getting this error:
無法將C:UniServer mpphp3F62.tmp"移動到static/images/slides/1/1.jpg"
很直接,對吧?找不到目標文件夾.
Pretty straight-forward, right? It can't find the destination folder.
我的問題是:如何引用所需的目標目錄?
引用是否相對于腳本在服務(wù)器上的位置?還是相對于 URL?還是 PHP DOCUMENT_ROOT
?還是操作系統(tǒng)的文件系統(tǒng)?或者別的什么?
Is the reference relative to the script's position on the server? Or is it relative to the URL? Or the PHP DOCUMENT_ROOT
? Or the OS's filesystem? Or something else?
我在 PHP 文檔中或在 SO.. 上的任何類似問題中都找不到答案.
I can't find the answer in the PHP documentation or indeed in any of the similar questions here on SO..
有人可以幫忙嗎?謝謝.
Can anyone help? Thanks.
推薦答案
跟蹤路徑的一個簡單方法就是在 index.php 中定義絕對路徑
A simple way to keep track of the path is just to define the absolute path in your index.php
define ('SITE_ROOT', realpath(dirname(__FILE__)));
然后像這樣使用它:
move_uploaded_file($_FILES['file']['tmp_name'], SITE_ROOT.'/static/images/slides/1/1.jpg');
這篇關(guān)于PHP:move_uploaded_file() 無法打開流:沒有那個文件或目錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!