Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't copy file with php copy

Posted on 2013-07-01
10
Medium Priority
?
1,349 Views
Last Modified: 2013-07-01
I get this message:

Warning: copy(http://www.sprinklerrepairpearland.com/contractor_seal2.gif) [function.copy]: failed to open stream: HTTP wrapper does not support writeable connections in /home/content/03/6424703/html/site_clone.php on line 43

Line 43 is copy($fip, $tip);

fip = http://www.sprinklerrepairkaty.com/contractor_seal2.gif
tip = http://www.sprinklerrepairpearland.com/contractor_seal2.gif

What's wrong? Do I need the absolute file path on the server?
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39290571
What's wrong is that you cannot copy a file to a URL and just have it show up there. Otherwise, I could run the same script and then start putting files onto YOUR server (big security risk, right?).

You need to run the script ON the server that hosts the sprinklerrepairpearland.com, and then specify a local directory/folder on that server.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39290575
If you're working with Apache, you must set permissions correctly for that folder: you can set them to 0777, but I see it is the root folder. I suggest you to store those images in another folder and set permissions for this new folder only to 0777. Giving 0777 to the root folder is bad, bad , bad practice :)

Cheers
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 2000 total points
ID: 39290686
To expand on what I was saying in my first comment, when you work with many of the file functions (copy, rename, file_get_contents, etc...), PHP will look at the filename and determine how to work with that particular filename.

So for example, if you say:
$contents = file_get_contents("test.txt");

Open in new window

Then PHP will look in the current directory on the current server's filesystem for a file called test.txt.

$contents = file_get_contents("/path/to/test.txt");

Open in new window

PHP will look in a folder called /path/to on the current server's filesystem for a file called test.txt.

$contents = file_get_contents("http://www.site.com/test.txt");

Open in new window

PHP sees "http://" and instead of checking the current server's filesystem, it gets a helping hand from another library that knows how to deal with URLs. So PHP passes the URL to that library (the HTTP wrapper), and the wrapper allows PHP to download the file contents.

However, there is no way to simply save a file to an HTTP address (you can use WebDAV, but even that is a different technology than plain ol' HTTP). You can pass data to HTTP like a form post or even a form with an attachment, but unless the receiving script is built to handle the attachments, that data will simply vanish after you upload it. That said, there's really nothing the HTTP wrapper can do to allow you to "write" files to a URL, which is why you get that error.

But you CAN write to the local filesystem, so if you were to create a PHP script on the destination server that looked like this:

copy("http://www.fromsite.com/from/file.jpg", "/path/to/file.jpg");

Open in new window

Then PHP will use the HTTP wrapper to read/download the file from "www.fromsite.com", and then once it has it in memory, it will save the file to the current server in /path/to/file.jpg.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39290687
giving 777 to the root folder will also cause php to fail if your host is running phpsuexec. Create a new directory and set it to 777 then you will be able to write to it.

Give this example a try:

http://stackoverflow.com/questions/724391/saving-image-from-php-url-using-php
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39290695
@experts - read the question more carefully. It is not a permissions issue (at least not yet):

"HTTP wrapper does not support writeable connections"
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39290716
@gr8gonzo is right.  You can copy From a URL but not To a URL.  Even if WebDAV was enabled on the destination server, you would have to be logged in to use it.  PHP thru the web server is not going to be allowed to do that.
0
 

Author Comment

by:Richard Korts
ID: 39290736
To gr8gonzo.

How do I get the "to" path; I know I can do that somehow in php; I tried realpath, it gave me nothing.

Thanks
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39290811
Hi rkorts,

That's not something I can answer without actually looking at your server's setup. You should have a folder structure somewhere on the server that holds the files for the "http://www.sprinklerrepairpearland.com" site. It's up to you to know where that folder is, and then simply set the path to it.

For example, if you had /www/html/sprinklerrepairpearland.com/htdocs, I would say that's your "to" path.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39290833
Are both of these web sites hosted on the same server?  If so, you may be able to get around this issue by using a file path.  But you will never be able to write to a URL.

If you cannot get to both files via file paths, you will need to write a web service that can run on the "to" server.  It will request the data from the "from" server and write it into its own directory tree.  You should be able to poke this web service with the "from" server to initiate the transfer whenever the updates are needed.
0
 

Author Closing Comment

by:Richard Korts
ID: 39290891
I thought of another way around this.

The sites ARE hosted on the same server. And bunches more to come.

Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question