2013-02-05 41 views
0

我與節點的工作,並表示和我有一樣寫文件到子目錄的node.js

public 
    img 
    css 
    js 
server.js 

在server.js用於寫入PNG文件,我有以下代碼目錄結構

fs.writeFile('testfile.png', imageData, function(err){ 

     res.send("file successfully created"); 

    }); 

這會在IE瀏覽器下的目錄結構

public 
    img 
    css 
    js 
server.js 
testfile.png 

如何創建根文件裏面的img目錄?只需使用​​,/img/testfile.png/public/img/testfile.png不起作用 - 不會創建任何文件。

幫助感謝!

回答

4

你可以做到這一點

'./public/img/testfile.png'

或者,你可以給這樣的

__dirname + '/public/img/testfile.png'

相對路徑此外,檢查目錄img的許可。可能是寫入權限沒有給出。

+0

做第一個工作嗎? img公開的不是當前目錄嗎? – algorithmicCoder

+0

糟糕。忘了添加「公共」,編輯..你檢查權限嗎? –

+1

沒問題......雖然我剛纔意識到我沒有重啓節點服務器!..這可能與我的問題有關:)可以接受你的答案。謝謝! – algorithmicCoder