michaeldrennen / Geonames

A Laravel (php) package to interface with the geo-location services at geonames.org.
MIT License
89 stars 38 forks source link

Problems with backslash (Windows, DIRECTORY_SEPARATOR) #43

Closed sngrl closed 3 years ago

sngrl commented 4 years ago

It seems like this problem is still here: https://github.com/michaeldrennen/Geonames/issues/18 PHP constant DIRECTORY_SEPARATOR on Windows system is backslash: "\" On MySQL query running it make a troubles:

# php.exe artisan geonames:install --country=EN --language=en
.............................................................
Inserting via LOAD DATA INFILE: D:\OpenServer\domains\project\storage\geonames\iso-languagecodes.txt
SQLSTATE[HY000]: General error: 7890 Can't find file 'D:OpenServerdomainsprojectstoragegeonamesiso-languagecodes'.
PDO::exec("LOAD DATA LOCAL INFILE 'D:\OpenServer\domains\project\storage\geonames\iso-languagecodes.txt'
    INTO TABLE geonames_iso_language_codes_working IGNORE 1 LINES
        (   iso_639_3,
            iso_639_2,
            iso_639_1,
            language_name,
            @created_at,
            @updated_at)
    SET created_at=NOW(),updated_at=null")
sngrl commented 4 years ago

@michaeldrennen you use DIRECTORY_SEPARATOR constant in two packages: Geonames & LocalFile.

Geonames requires Laravel, so it's possible to use dotenv features and change DIRECTORY_SEPARATOR to env('DIRECTORY_SEPARATOR', DIRECTORY_SEPARATOR) in the Geonames package source code, and don't forget to add line DIRECTORY_SEPARATOR=/ to .env file.

LocalFile package need to change too, in method split() - add optional attribute $directorySeparator with default value.

CamaleonGamer commented 4 years ago

Hi, for fix this problema i added addslashes() to $absoluteLocalFilePathOfIsoLanguageCodesFile in the file IsoLanguageCode.php and it would be like this:

$absoluteLocalFilePathOfIsoLanguageCodesFile = addslashes(self::downloadFile($this, $remotePath, $this->connectionName));

The same for the following files: InsertGeonames.php -> $absolutePathToMasterTxtFile = addslashes($this->combineTxtFiles());

I hope it helps!!!

jomosen commented 4 years ago

Hi, for fix this problema i added addslashes() to $absoluteLocalFilePathOfIsoLanguageCodesFile in the file IsoLanguageCode.php and it would be like this:

$absoluteLocalFilePathOfIsoLanguageCodesFile = addslashes(self::downloadFile($this, $remotePath, $this->connectionName));

The same for the following files: InsertGeonames.php -> $absolutePathToMasterTxtFile = addslashes($this->combineTxtFiles());

I hope it helps!!!

I use windows and I had the same problem but with the changes you mention works perfectly. Thanks @CamaleonGamer

CamaleonGamer commented 4 years ago

Hi, for fix this problema i added addslashes() to $absoluteLocalFilePathOfIsoLanguageCodesFile in the file IsoLanguageCode.php and it would be like this: $absoluteLocalFilePathOfIsoLanguageCodesFile = addslashes(self::downloadFile($this, $remotePath, $this->connectionName)); The same for the following files: InsertGeonames.php -> $absolutePathToMasterTxtFile = addslashes($this->combineTxtFiles()); I hope it helps!!!

I use windows and I had the same problem but with the changes you mention works perfectly. Thanks @CamaleonGamer

Good thing it was helpful! Greetings!

michaeldrennen commented 3 years ago

I just committed some code that should fix this issue. @CamaleonGamer was on the right track. Let me know if this resolves the issue. If not, I will dust off my Windows machine and take a deep dive.

CamaleonGamer commented 3 years ago

I just committed some code that should fix this issue. @CamaleonGamer was on the right track. Let me know if this resolves the issue. If not, I will dust off my Windows machine and take a deep dive.

Excellent, Thanks so much! @michaeldrennen