Page 2 of 2

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Mon May 22, 2017 5:34 am
by Celauran
Because of the backslashes, you've got mismatched quotes, leading to that syntax error. Also, C:\stuff isn't a URL, it's a path on a filesystem.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Mon May 22, 2017 5:36 am
by simonmlewis
I tried it with just \, and that failed too. Or is escaping them doing like so:

\\

Oh and I know. Just a figure of speech!

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Mon May 22, 2017 5:50 am
by Celauran
Yes, you need to escape backslashes with other backslashes.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Mon May 22, 2017 6:33 am
by simonmlewis
Ok that worked - i think.
I deleted a copy of the file being copied over and ran it again, and locally it seems to have worked. But not convinced my code that checks on the two databases are all working. So need to check that really.

And then, see how to make that script work in a live environment. In theory, I just use the website address rather than the c:\ string ??

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Mon May 22, 2017 8:38 am
by simonmlewis
Trying to see how to make the right sort of connection here, to multiple databases (some will not be on the same server).

For now, locally:

Code: Select all

  $dbuk = new PDO('mysql:dbname=site_uk;host=localhost', 'root', '');
  $dbie = new PDO('mysql:dbname=site_ie;host=localhost', 'root', '');

       $query = $dbuk ->prepare ("SELECT * FROM products WHERE id = '$dbie '");
         while ($row = $query->fetch(PDO::FETCH_OBJ)) 
           {

}
This doesn't work. Probably as nothing is being executed, but am I close?

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Mon May 22, 2017 9:57 am
by simonmlewis
I've sorted this bit now.
I forgot that this whole site has one core connection, so I am using that for the local one, and then a separate $pdo-query for the other site.
Then I just call it in the query at the start variable, rather than at the end.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Fri May 26, 2017 3:22 am
by simonmlewis
What sort of query string would it be for the file location?
Would it just be the http://..... or the hosted file location within the filing structure?

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Tue May 30, 2017 5:30 am
by Celauran
If you're trying to retrieve a file from a remote host, use the URL, not the file path. http://some.site.com/assest/images/foo.jpg or whatever.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Tue May 30, 2017 5:37 am
by simonmlewis
But if saving it, as in copying over, the 'pick up' point is the URL, but the storage string will be a properly file string won't it, which I'll need to get from the host.
Unless there is a clever way of me finding out what it is?

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Tue May 30, 2017 6:50 pm
by Celauran
Wouldn't you already know? I mean, you're requesting a specific image, and you're basing that request on something. You've got logic on how/where to store images for your products, you know which product you're requesting an image for... Am I missing something here?

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Wed May 31, 2017 2:26 am
by simonmlewis
I am copying data from a database - that's easy.
I am copying one image from a location. I know the location from it's URL.
But it needs to be copied *to* somewhere. This is on a live hosting server. I am not a 'server' person, so I don't know the 'raw' file string of where that is stored. It won't be the URL of the local website, or would it simple me $filestring = /images/productphotos/ which is how I echo the images??
<img src='/images/productphotos/$row->photoprimary' />.

Is it as straight forward as that??

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Wed May 31, 2017 5:08 am
by Celauran
Sure, you're getting the filename from the database, but that also contains information about what that image belongs to; product, category, etc. You're retrieving the image from a different location, but the logic to save it should be the same as for a newly uploaded image.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Wed May 31, 2017 5:14 am
by simonmlewis
I don't think you get my issue here.
The image contains none of that. It's a file.
I just need to tell PHP *where the file needs to be placed*.
It's current location differs from it's copied destination.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Wed May 31, 2017 5:27 am
by Celauran
I guess I don't get your issue. I assumed you were simply retrieving missing images for existing entries in the database.

Re: How do I copy files across, using PHP - host 1 > host 2?

Posted: Wed May 31, 2017 5:40 am
by simonmlewis
I am just copying an image from one site to another.
I'm running an INSERT script with the data from another database. That's fine.
I have located the file on the other site. That's fine.
But it's the new storage destination that I am stuck on. It might be something I have to ask me hosts about.
How does the script know where to store it - that's the issue. The physical folder.