是否可以将图像从网络复制到硬盘?
我正在尝试创建一个仅供个人使用的页面。我想要做的是,创建一个系统,通过该系统我可以将图像下载到本地硬盘,直接通过 localhost(如 WAMP)提供链接。我尝试这样做的原因是,我希望图像自动排序到我的硬盘上。我的表单字段将是这样的
<form method="POST" action="process.php">
<input type="text" name="URL" id="URL" />
<input type="text" name="category" id="category" />
<input type="text" name="subcategory" id="category" />
<input type="submit">
</form>
现在,在 process.php
中,
//This is just a sample... So please ignore the roughness of the coding
copy($_POST['url'],$_POST['category']."/".$_POST['subcategory']."/somename.jpg");
// If you noticed, the categories and subcategories are actually the name of directory, where I want the picture to go be saved....
我认为我的方法是错误的。我怎样才能实现这样的目标?
错误
Warning: copy(images/image.jpg) [function.copy]: failed to open stream: No such file or directory in
I am trying to create a page for just personal use. What I want to do is, create a system through which I can download images to my local hard disk, directly by providing the link through a localhost like WAMP. The reason I am trying to do is, I want the images to be automatically sorted onto my hard disk. My form field will be something like this
<form method="POST" action="process.php">
<input type="text" name="URL" id="URL" />
<input type="text" name="category" id="category" />
<input type="text" name="subcategory" id="category" />
<input type="submit">
</form>
Now, in the process.php
//This is just a sample... So please ignore the roughness of the coding
copy($_POST['url'],$_POST['category']."/".$_POST['subcategory']."/somename.jpg");
// If you noticed, the categories and subcategories are actually the name of directory, where I want the picture to go be saved....
I am thinking my approach is wrong. How can I achieve something like this?
Error
Warning: copy(images/image.jpg) [function.copy]: failed to open stream: No such file or directory in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 php.ini 中的
allow_url_fopen
为 true 并且您的PHPVERSION
>= 4.3.0 您的代码应该可以工作。If
allow_url_fopen
is true in the php.ini and yourPHPVERSION
is >= 4.3.0 your code should work.好吧,我用curl代替来实现我的期望。这是一段代码
Ok, I used curl instead to achieve what i am expecting. Here is the piece of code
你可以先从指定的url下载php脚本文档,然后给出http-client链接来下载本地存储的文件。或将文档内容放入输出流:
you can first download from php script document from specified url, then give http-client link to download locally stored file. or put document content to output stream: