merlino Posted January 5, 2011 Share Posted January 5, 2011 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 More sharing options...
CYTechnologies Posted January 5, 2011 Share Posted January 5, 2011 Hello,So the main issue here is moving the images over so they will work from an internal location? Right? Link to comment Share on other sites More sharing options...
merlino Posted January 5, 2011 Author Share Posted January 5, 2011 I have the url of the images (these are on an external server) and I want it stored locally on my server.Can Smarty or other do this..? Link to comment Share on other sites More sharing options...
CYTechnologies Posted January 5, 2011 Share Posted January 5, 2011 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 More sharing options...
merlino Posted January 5, 2011 Author Share Posted January 5, 2011 thanks for the suggestions!I will work on these points Link to comment Share on other sites More sharing options...
merlino Posted January 5, 2011 Author Share Posted January 5, 2011 Which table of the Prestashop DB stores the image local urls? Link to comment Share on other sites More sharing options...
CYTechnologies Posted January 5, 2011 Share Posted January 5, 2011 They are stored in the table ps_image.Keep in mind the file names of the images are PRODUCT_ID-IMAGE_ID-SIZE :-) Link to comment Share on other sites More sharing options...
StoCo Posted January 5, 2011 Share Posted January 5, 2011 Hi there,Take a look at this post http://www.prestashop.com/forums/viewthread/85662/job_offers_and_paid_services/turbo_boost_your_csv_imports_with_store_commander_for_prestashop/Store Commander does precisely what you are looking for i.e. Import images from external urls or images placed on a server without being left with duplicates. Link to comment Share on other sites More sharing options...
siadmin Posted January 10, 2011 Share Posted January 10, 2011 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 More sharing options...
siadmin Posted January 10, 2011 Share Posted January 10, 2011 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 More sharing options...
CYTechnologies Posted January 10, 2011 Share Posted January 10, 2011 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 More sharing options...
siadmin Posted January 10, 2011 Share Posted January 10, 2011 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 More sharing options...
Minotauro Posted January 24, 2011 Share Posted January 24, 2011 Take a look at this tool, it almost everything that you are looking for http://www.wasato.net/en/providers-connector.html Link to comment Share on other sites More sharing options...
shellxie Posted April 29, 2012 Share Posted April 29, 2012 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 More sharing options...
006bonetti Posted May 29, 2012 Share Posted May 29, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now