flashjunkiejoe Posted March 12, 2012 Share Posted March 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/ Share on other sites More sharing options...
cpd Posted March 12, 2012 Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326508 Share on other sites More sharing options...
xyph Posted March 12, 2012 Share Posted March 12, 2012 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] Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326510 Share on other sites More sharing options...
flashjunkiejoe Posted March 12, 2012 Author Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326519 Share on other sites More sharing options...
xyph Posted March 12, 2012 Share Posted March 12, 2012 You'd need to provide us with an example CSV file that a customer would send. Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326526 Share on other sites More sharing options...
flashjunkiejoe Posted March 12, 2012 Author Share Posted March 12, 2012 Not sure why that would help, but it's attached. Thanks. 17766_.zip 17767_.zip Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326534 Share on other sites More sharing options...
Psycho Posted March 12, 2012 Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326545 Share on other sites More sharing options...
flashjunkiejoe Posted March 12, 2012 Author Share Posted March 12, 2012 Yup, is exactly what I was thinking. Thanks for your time and advice. I'm just going to go with my original idea which is just to keep everything within an online application. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/258761-import-image-via-csv-format/#findComment-1326550 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.