开发者

Get full file name in PHP with file dialog

I want to get a filename to upload it with PHP to a FTP Server. But anytime I use the 开发者_如何学运维I only get the filename itself, not the needed FULL path for fput...Ideas? Everybody complaining on how to extract the filename from the path but I WANT the path :D


Well, the answer still is: you can't. Not via the browser anyway.

It almost sounds as if you're writing an application that perhaps should not be a browser application, like some sort of backup application.


$_SERVER['DOCUMENT_ROOT'];

I think this is what you're looking for if you're automating the ftp from another server. If you're just letting the user interact via a browser, the file will be in a temporary folder on the server uploaded to and can be handled like this -

$basepath = $_SERVER['DOCUMENT_ROOT'] . HOME;
$directory_img = $basepath.'images/';
$fieldname = 'file';
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
or error('not an HTTP upload', $uploadForm);  

$src_name = $stock.$nbr.".jpg";
$uploadFilename = $directory_img.$src_name;

I've pasted here just the code that mostly pertains to your question. Note that there may be variables that I've defined outside of these lines of code.


If I understand your question, the answer is you can't with PHP. Since PHP is a server side script it has no access to the clients file directory structure. You require a client side script to browse the client drive, like JavaScript. You can then tell PHP the file is coming with an Ajax call or similar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜