0

Been trying to figure this one out for months. I actually came across a similar question here but seems like what I want to do isn't really possible or hasn't been done?

Basically if you are using PHP and Html to upload an image to your database this is how you would start:

<?php
if (isset($_POST['submit'])) {
    print_r($_FILES['my_little_image']); //gives the image name, size, type, temp location, etc
}
?>

<form method="post" enctype="multipart/form-data">
<input type="file" name="my_little_image">
<button type="submit" name="submit">Upload</button>
</form>

But I've got an image on my computer, not a remote source or url, which must land up in my online mysql database, by inserting something like "C:/my_folder/my_little_image.jpg" in a .csv file and then using PHP to somehow grab that image, do what the $_FILES['my_little_image'] and move_uploaded_file() etc does, and see the path to the uploaded file in my database. So the result in my DB would be https://mydomain_example.com/uploads/my_little_image.jpg

Now excuse the elaborate question, I'm sure it could be said in lesser words but English is not my birth language. Is this possible?

Edit: My current users are using CSV files to upload images to my database using remote Urls they previously uploaded elsewhere (or on my website) - but I'm trying to figure out if there's a way to do this process without the use of remote urls. Basically, my users want a way of getting an image from the their own hard drive just by pasting the local url "C:/path/to/their/image" into the CSV file.

ArabianMaiden
  • 505
  • 7
  • 24

1 Answers1

0

It is possible to send an image in a csv file, just not the way you imagined.

If you sent the path on your local computer to the image in the csv file, then the php code on the server would have to be able to access that path - probably not really convenient or effective.

You could either use a cloud file hosting provider (e.g. google drive, dropbox, etc) that you can easily access both from your local computer and your server and include the url or other identifier used by the provider in the csv file.

Alternatively, you can actually send the image within the csv file with base64 encoding (you probably want other fields in the csv indicating the image type and the name).

Be warned: base64 encoded images may take about 33% more space up than their binary versions.

A third possibility is to package all the images into a zip or rar file, upload this file along with the csv and the csv file refers to the images by name in the package.

I must reiterate: accessing a file on a local computer from a server in the Internet requires a lot of configuration on the local computer and network, most likely installation of some kind of a file transfer service (ftp or webdav server), and has security implications (your clients have to open up their network and their computer to be accessible from the Internet).

You may have to create a desktop application for them that packeges the images and other data in a format required by your application, if your clients are not technologically savvy enough to use one of the three options I outlined above.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • Both of these solutions mean that the image has to be uploaded somewhere beforehand, thereby gaining the url and base64 encoding (which most of my target audience users will not have knowledge on how to get that) – ArabianMaiden Dec 25 '19 at 22:57
  • Base64 encoding does not require anyone toupload images to anywhere. You can convert images in place. Btw, if you cannot expect your users to upload files to google drive or dropbox, then you can't expect them to configure their network to allow your php code to access their computer either. Trust me, the latter is a lot more difficult and a lot less secure. Also, you can create your own web page that converts images to base64. Not particularly difficult. – Shadow Dec 26 '19 at 00:25