最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Upload file without form - Stack Overflow

programmeradmin2浏览0评论

Upload file without form Yes i used the search button but i just couldn't find the solution i need. Is there any way to upload a file so that user wouldn't need to press any form buttons?

My first idea was to use CURL but then i remembered that CURL is server sided.

I know it's possible thru Java and/or Flash but is there any way to do that using PHP & OR Javascript?

Edit: Thanks for clearing this for me but... But what about PHP based FTP upload?*

Upload file without form Yes i used the search button but i just couldn't find the solution i need. Is there any way to upload a file so that user wouldn't need to press any form buttons?

My first idea was to use CURL but then i remembered that CURL is server sided.

I know it's possible thru Java and/or Flash but is there any way to do that using PHP & OR Javascript?

Edit: Thanks for clearing this for me but... But what about PHP based FTP upload?*

Share Improve this question edited Jan 18, 2011 at 15:13 Ardi Vaba asked Jan 18, 2011 at 15:03 Ardi VabaArdi Vaba 1891 gold badge4 silver badges11 bronze badges 14
  • 1 I certainly hope not. I don't want any application or web form uploading files from my puter without me clicking anything. – Matt Commented Jan 18, 2011 at 15:06
  • @Ardi You obviously cannot do it with PHP, since it is server-sided too. JavaSript can do it. Do you possibly use a JavaScript library? btw I am assuming that the file is already selected via an INPUT type file field. – Šime Vidas Commented Jan 18, 2011 at 15:06
  • @Šime: if you're talking about ActiveX and consorts, that won't work crossbrowser and even then, it wouldn't work without warnings/confirmation dialogs. – BalusC Commented Jan 18, 2011 at 15:08
  • 1 Best you can achieve is auto submit the form once user selects a file. You can't and it must never be possible for client side script to auto-select file from the visitor file system!! – Shadow Wizzard Commented Jan 18, 2011 at 15:08
  • @Šime: that still require user interaction to select the file. The OP was asking for a way without any user interaction. – BalusC Commented Jan 18, 2011 at 15:10
 |  Show 9 more ments

3 Answers 3

Reset to default 4

No, it isn't. That would have been a huge security hole. Your best bet is really an officially signed(!) Java applet. An unsigned or a manually signed one would still emit scary warnings to the enduser before proceeding.

I have found a solution. Copy does not take local files and the example of submiting the file does not work if it is local. What you have to do is:

file_get_contents("file:///C:\img.jpg")

then write to a text file the contents in the server (for example /uploads/img.txt) and rename to the same extension of the file to see the image. It really works with any kind of file.

what do you mean without pressing any form buttons ? well you could do a javascript document.getElementById('FORM_NAME').submit(); if you want some function in javascript to do the upload , where FORM_NAME is the id or your current html form .

but you CAN NOT make your webpage select the file to upload , you have to let the user select the file in an <input type="file"> element .

otherwise use a java applet

发布评论

评论列表(0)

  1. 暂无评论