Jump to content

import products phase - create images on the server using external URL image links


merlino

Recommended Posts

hello everybody,

I'm tring to create a script in php which can import product from a CSV file and create images on the server(where my prestashop site is) from external url images.
I know from the Back Office with the function "import" manually this is possible.

So I ask here to all the experts a suggestion or a tip on how to make this with a script...if there's a particular table on the DB where the urls are stored or if there's a particolar smarty function to use..

thanks for the suggestions

Link to comment
Share on other sites

If you want to transfer an image from one server to another, no smarty can not handle this, if you are looking to just hotlink that is different.

Your import script would have to use something a long the lines of 'file_get_contents()' (http://us2.php.net/manual/en/function.file-get-contents.php)

So your process would be as such:

1. use file_get_contents to read the external image source.
2. Create a new image on your server (using fopen())
3. Write the information you received from file_get_contents into the new image you created in step2.
4. Store your new image name into your import csv or array and save it to the db.

:-)

Link to comment
Share on other sites

If you want to transfer an image from one server to another, no smarty can not handle this, if you are looking to just hotlink that is different.

Your import script would have to use something a long the lines of 'file_get_contents()' (http://us2.php.net/manual/en/function.file-get-contents.php)

So your process would be as such:

1. use file_get_contents to read the external image source.
2. Create a new image on your server (using fopen())
3. Write the information you received from file_get_contents into the new image you created in step2.
4. Store your new image name into your import csv or array and save it to the db.

:-)


I'm not a php or bash expert, but i probably wouldve written something like
foreach $url {
exec("wget $url");
}



pretty sure you can add a target dir to wget..

i presume you have some way of then linking them to whatever your using them for? there location wont be stored in the database, unless you create your own table and have a INSERT INTO new_table query to record the id and location of each file.

Link to comment
Share on other sites

That said, your task is to import products and images at the same time.. so all you really need is to automate the back office import tool.. this requires editing the file AdminImport.php find it in site.com/admin/tabs/ ..there are threads floating around here that will tell you what to do.. search for Automatic Import ..or other things like that.. Store Automation, import products autmatic etc. etc.

Link to comment
Share on other sites

Howdy siadmin,

Not sure exec is the way to go here. 'exec' is used to execute an external program on the server or run shell commands. This can get dangerous if you do not parse your $url properly as someone can enter a malicious url.

With an image you really only want the data, fopen, or file_get_contents can perform this safely without interacting with the system itself. Always be cautious when using exec, if its not needed don't use it.

Link to comment
Share on other sites

Howdy siadmin,

Not sure exec is the way to go here. 'exec' is used to execute an external program on the server or run shell commands. This can get dangerous if you do not parse your $url properly as someone can enter a malicious url.

With an image you really only want the data, fopen, or file_get_contents can perform this safely without interacting with the system itself. Always be cautious when using exec, if its not needed don't use it.


thats fair.. i've only ever used it to execute scripts that i've written myself so that hasnt been an issue as yet. thanks though.

that said, in my limited knowledge i find myself wondering why you wouldnt have the same problem with the php commands.. your still going to save the file to your server and then potentially execute it some other way.. what happens if php saves site.com/virus.exe ?? ..surely you need an additional instruction to protect against this..
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

This post is very useful to me.

"They are stored in the table ps_image.

 

Keep in mind the file names of the images are PRODUCT_ID-IMAGE_ID-SIZE :-)"

 

I have questions as"

1)how can I see the imgae url in the table ps_image with PhpMyAdmin? I tried and can see nothing in the table.

2)where is the file PRODUCT_ID-IMAGE_ID-SIZE?

 

Thanks,

Link to comment
Share on other sites

  • 1 month later...

Hi,

I need to do pretty the same job as merlino, where can I find script for the tool of back office, which ensures that importing??

I want to change the code, but i don't know, where it is located on the file system.

 

BTW where are all these tool files? I'm having the same problem with functionality of groups and customers (need to alter it a little bit), but everybody just ads his own modules to buy..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...