webactor Posted January 12, 2009 Share Posted January 12, 2009 Hello I have made a php code that import a CSV file into a table in MySQL database on the same website. My problem is that I want the php code to download CSV file from a library located above Wwwroot Is there anyone who knows a solution to this? Or maybe can guide me in the right direction Hope can help me Kimo Quote Link to comment https://forums.phpfreaks.com/topic/140520-php-code-to-download-csv-file-from-a-library-located-above-wwwroot/ Share on other sites More sharing options...
rhodesa Posted January 12, 2009 Share Posted January 12, 2009 what is the full path to the script and the full path to the csv file? php shouldn't have any problems reading directories above wwwroot unless there are specific access restrictions in place Quote Link to comment https://forums.phpfreaks.com/topic/140520-php-code-to-download-csv-file-from-a-library-located-above-wwwroot/#findComment-735344 Share on other sites More sharing options...
webactor Posted January 14, 2009 Author Share Posted January 14, 2009 The full path to the script is /wwwroot/impot.php And to the csv file, the full path is /import/file.csv Attributes to /import is 666 And to /wwwroot also 666 The code is $query = "truncate table testkart"; $query = @mysql_query($query,$link); $handle = fopen ('..\..\..\import\file.csv', 'r'); while (($data = fgetcsv($handle, 1000, ';', '"')) !== FALSE) { $query = "INSERT INTO testkart VALUES ('". implode("','", $data)."')"; $query = @mysql_query($query,$link); } mysql_close($link); the error I get is Warning: fopen(..\..\..\import\file.csv) [function.fopen]: failed to open stream: No such file or directory in And the file is there… I have tried with path as \import and ..\import and so on,, same error every time… Best regards Kimo Quote Link to comment https://forums.phpfreaks.com/topic/140520-php-code-to-download-csv-file-from-a-library-located-above-wwwroot/#findComment-737087 Share on other sites More sharing options...
rhodesa Posted January 14, 2009 Share Posted January 14, 2009 $handle = fopen (../import/file.csv', 'r'); Quote Link to comment https://forums.phpfreaks.com/topic/140520-php-code-to-download-csv-file-from-a-library-located-above-wwwroot/#findComment-737099 Share on other sites More sharing options...
Ninjakreborn Posted January 14, 2009 Share Posted January 14, 2009 Rhodesa answered your question, I just want to add some info into this. You have fallen prey to a common problem when dealing with files and directories. Long ago I use to get very confused when it came to directories and how to access certain files in certain places. I use to get confused on using ../ and ../../ and ./ and everything else when I first started working with files and directories. It took me awhile to finally learn exactly how the structure would go in every situation. Basically let's say you are trying to accessing ROOT/tempfolder/tempfolder2/file.php In this situation you are trying to access file.php. The following legend is ALWAYS application "/" before what you are seeking will always start at root directory. So "/tempfolder" will access the tempfolder directory. Not using "/" before hand automatically means you are trying to access whatever is in the DIRECTORY YOU ARE CURRENTLY IN. So..if you are in tempfolder and you do "tempfolder2/file.php" you can access the file.php. However if you do "/tempfolder2/file.php" you cannot access it. You would have to do "/tempfolder/tempfolder2/file.php" instead. The reason being is because if you are in that folder and you use the "/" in front of what you are looking for then that means you are starting your search at the root level. Not putting the "/" is signifying that you want to start your url from the folder you are currently in. So if there was a file under tempfolder that stated "index.php" and you were IN the tempfolder location you could access that file either "/tempfolder/tempfolder2/index.php" or you could simply use "index.php". Again the difference is with the "/" symbol. When you use it you start your search at root and have to specify the exact location of your file..if you are wanting to look in your same folder then do not use that and you can just climb from the one you are in. There are other symbols as well. If you are in tempfolder2 and want to backup just to access something behind you then you can actually use the "/" to put in the full url or you can go ahead and access it via the backup command. So for example you have a file in tempfolder instead called "index.php" and your in tempfolder2. You can either access the full url "/tempfolder/index.php" or you can back up and grab it instead using "../index.php". The ../ will kick you back one folder then you can access whatever is in that folder. The ../ is a repeatable command. Everytime it is used it takes you back one folder. So if you want to go back 2 folders you use ../../ 3 folders would be ../../../ and generally you don't need to go to the trouble when you can access the folder directly using "/" command. But it is nice to know and thinking on this can help solve your directory issues. Quote Link to comment https://forums.phpfreaks.com/topic/140520-php-code-to-download-csv-file-from-a-library-located-above-wwwroot/#findComment-737111 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.