Jump to content

Import Image via CSV Format


flashjunkiejoe

Recommended Posts

I am a developer in PHP but have run into an obstacle and was hoping for some insight. I am attempting to do something a little complicated I fear but perhaps there is a solution.

A client of mine is offering CSV templates for customers to use to BATCH UPLOAD item's to their account. This is self explanatory in the fact that I know how to import a .CSV with PHP and I know how to properly insert it into the database.  My question is this: What if we wanted to offer a way for the customer to insert an image into the .CSV template.  By the time the .csv reached my PHP code would the image still be in a format where it could be uploaded to a directory on the server?  I have not found anything on the web where anyone has tried this.

 

Again, the customer will insert an image from their hard drive into a row within the .CSV template. My code will parse the .CSV row data and if the image is still in tact...will then upload the image to a director with more code.

 

Thanks for any help.

 

Joe

Link to comment
Share on other sites

Working through your question logically. When you send a CSV file to someone over the web containing an image, the image appears their end. This indicates the image is inside the CSV file. As to whether or not you can upload the image I'm unsure; though I would imagine its possible.

Link to comment
Share on other sites

No, this isn't possible. You need the user to upload the image directly. They can't just give you the location of the image file on their hard drive.

 

This is done through a form using the 'file' input type, or through a browser plugin such as Java or Flash.

 

Those plugins could theoretically provide the functionality you desire.

 

[edit] Oh, so the binary data is sent through the CSV file? If this is the case, then yes it's possible. Just dump the binary data into a new file with the correct extension. [/edit]

Link to comment
Share on other sites

Correct, I am aware that I cannot reach their hard drive. My question was about the image format and whether it holds up during the upload process, well enough to insert it into the database as BLOB, or just fput it into a folder somewhere.  I was not sure if it was actually BINARY DATA that was being sent and if so I suppose I could work with that within my class. If not...then no.

Link to comment
Share on other sites

You can't do what you are wanting to. User's can't simply drop an image into an Excel spreadsheet and then convert it to CSV. For one, images in Excel do not exist IN the cells. They float outside the cells. At least I've never seen a way to make the images exist within a cell. And, even if they could, as soon as you convert the file to a CSV, Excel will strip out the images. The user would need some way to extract the binary content from the image and then paste that into the appropriate cell in Excel before converting to CSV.

 

I assume the user is uploading the CSV file. The only workaround I can think of that would not require the user to upload all the individual images and not building/buying a Java applet would be to have one additional upload field for the image. Have the user put the images in a zip file with all the images named such that they correspond to the data in the spreadsheet (product code or some other unique value). You could then open the zip file and put the images in a temp directory. Then when processing the CSV file, check for a matching image in the temp and move to a permanent location. When complete, delete the temp directory and any remaining files.

 

Or, you could import the CSV and then provide an interim page of all the imported records along with an upload field for each record. The user could then select the appropriate image for each record that was processed.

 

There are definitely some alternative workflows, but I don't see any possibility of doing what you are trying to achieve that would be easier since having a user extract binary data from a file seems a little too techie for most.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.