Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Connection to the FTP server


Chaima

Recommended Posts

I'm preparing a script that convert an (.xls) file to (.csv ) . It works in local environment but when I put it in The FTP it won't work because of the parameters of the server root for sure !


this is my code below ! Can anybody tell me what to do so it can be accepted by FTP



<?php
//Afffichage des erreurs PHP
error_reporting(E_ALL);

$DOC_ROOT = $_SERVER['DOCUMENT_ROOT'];
$BASE_URL = preg_replace("!^${DOC_ROOT}!", '', $BASE_DIR);
//$DOC_ROOT = substr($DOC_ROOT, -1) == "/" ? $DOC_ROOT : $DOC_ROOT."/";

//Mon site se trouve dans le www/web/
$DIR_SITE = $DOC_ROOT."/";

$fichierIN = $DIR_SITE."/export_tarifs.xls";
$fichierOUT = $DIR_SITE."/export_tarifs.csv";

// On importe PHPExcel
$phpXlFile = $DIR_SITE."../batchs/Classes/PHPExcel.php";
$phpXLfactory = $DIR_SITE."batchs/Classes/PHPExcel/IOFactory.php";
if( !file_exists($phpXlFile)){
echo "<br> Erreur : Fichier $phpXlFile introuvable";
exit();
}
if( !file_exists($phpXLfactory)){
echo "<br> Erreur : Fichier $phpXLfactory introuvable";
exit();
}
require_once $phpXlFile;
require_once $phpXLfactory;


if( !file_exists($fichierIN)){
echo "<br> Erreur : Fichier $fichierIN introuvable";
exit();
}



try {
$inputFileType = PHPExcel_IOFactory::identify($fichierIN);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($fichierIN);

$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objWriter->save($DOC_ROOT.'/export_tarifs.csv');
echo 'File saved to csv format';

} catch(Exception $e) {
die('Error loading file "'.pathinfo($fichierIN,PATHINFO_BASENAME).'": '.$e->getMessage());
}

?>

Link to comment
Share on other sites

If the code is working in your local environment - it means there is no issue with the code. It may be environment issues - particularly the folder in which you want the file to be written should have the required permission set to enable the script to write.

 

What error does the server give you? Is it able to read the file and fail in processing the output or does it not read the file at all?

 

More inputs would help :)

Best Regards,
Gaurav

Link to comment
Share on other sites

Hello ,

 

When I run the script I got this 

 

Erreur : Fichier /batchs/Classes/PHPExcel.php introuvable

 

The script can't read any path ! 

 

And i checket the access to the folder and the files it's 755 and 644 so there's no problem with the access I guess 

Link to comment
Share on other sites

OK, 

 

So what this means is .. it doesn't find the file PHPExcel.php.

1. You have to verify the file exists on your server so login to file manager and verify you can see /batchs/Classes/PHPExcel.php.

2. Verify from root if the path is valid, just in case you copied /batchs within includes(for example) or any other folder...

3. You server is giving null for $DIR_SITE, thus review the path and you can simply give exact path instead of relative path using $DIR_SITE.

 

HTH

Best Regards,
Gaurav

Link to comment
Share on other sites

I verified it many times the paths are good ! the PHPExcel exists in the path that I wrote in the code the access too !

And i gived the exacte paths for all but it wont work 

 

 

here's my new code 

 

<?php
//Afffichage des erreurs PHP
error_reporting(E_ALL);


$DOC_ROOT = $_SERVER['DOCUMENT_ROOT'];
$BASE_URL  = preg_replace("!^${DOC_ROOT}!", '', $BASE_DIR); 
//$DOC_ROOT = substr($DOC_ROOT, -1) == "/" ? $DOC_ROOT : $DOC_ROOT."/";


//Mon site se trouve dans le www/web/
//$DIR_SITE = $DOC_ROOT."/";
$DIR_SITE = $BASE_URL."/";




$fichierIN = $DIR_SITE."/web/export_tarifs.xls";
$fichierOUT = $DIR_SITE."/web/export_tarifs.csv";


// On importe PHPExcel
$phpXlFile = $DIR_SITE."web/batchs/Classes/PHPExcel.php";
$phpXLfactory = $DIR_SITE."web/batchs/Classes/PHPExcel/IOFactory.php";
if( !file_exists($phpXlFile)){
 echo "<br> Erreur : Fichier  $phpXlFile introuvable";
 exit();
} 
if( !file_exists($phpXLfactory)){
 echo "<br> Erreur : Fichier  $phpXLfactory introuvable";
 exit();
} 
require_once $phpXlFile;
require_once $phpXLfactory;




if( !file_exists($fichierIN)){
 echo "<br> Erreur : Fichier  $fichierIN introuvable";
 exit();
} 






try {
    $inputFileType = PHPExcel_IOFactory::identify($fichierIN);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($fichierIN);


$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objWriter->save($DOC_ROOT.'/web/export_tarifs.csv');
echo 'File saved to csv format';


} catch(Exception $e) {
    die('Error loading file "'.pathinfo($fichierIN,PATHINFO_BASENAME).'": '.$e->getMessage());
}


?>
Link to comment
Share on other sites

Using your browser you should be able to open the file by typing the URL directly for example

 

http://www.yoursite.com/web/batchs/Classes/PHPExcel.php [if web folder is in root.. if it is in catalog or anything else .. this is what you have to detect.. the actual path]

 

Or you may create a simple "Hello World" page in PHP and save it in same location as PHPExcel.php to see if the path is correct. If you cannot open the file directly in browser, there is something wrong with the path (placing ../ or / or something else that is required to make it work)

Best Regards,
Gaurav

Link to comment
Share on other sites

En tapant

 

http://www.yoursite.com/batchs/Classes/PHPExcel.php ça me retourne pas 404 not found il me retourne plutôt une page vide ! donc il arrive à accéder au fichier PHPExcel et à le lire vu qu'en testant la meme chose en local il me retourne une page vide !

 

Donc le chemin est correct !

Que puis je tester encore?

Link to comment
Share on other sites

Ok, took some help from Google and I could understand the previous post.

 

Well you get a blank page in browser and that is a good news... now next thing to look for is ..in which location does your PHP code (the one you have mentioned above) reside? Is this code in the root ? or any sub-folder?

 

All you have to now check is to get the exact path for your code to access PHPExcel.php..

 

HTH

Best Regards,
Gaurav

Link to comment
Share on other sites

Hi ,

 

I put that file (convert.php) directly under the root : the path is   ==>      www.monsite.com/convert.php

 

and PHPExcel.php under ==>    /web/batchs/Classes/PHPExcel.php    

 

I got a blank page :/ what can I do now ? 

Link to comment
Share on other sites

If you got no errors.. it means convert.php is getting called now.

 

Add few echo command to the following block to see if the code is being called .. or if the file is getting exit even before reaching try block..

try {
    $inputFileType = PHPExcel_IOFactory::identify($fichierIN);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($fichierIN);


$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objWriter->save($DOC_ROOT.'/web/export_tarifs.csv');
echo 'File saved to csv format';


} catch(Exception $e) {
    die('Error loading file "'.pathinfo($fichierIN,PATHINFO_BASENAME).'": '.$e->getMessage());
}

Best Regards,
Gaurav

Link to comment
Share on other sites

look at your (catalog)includes/configure.php file

 

there you have a DIR_WS_CATALOG

and a DIR_FS_CATALOG

See the difference between the two ? (faites attention à la difference entre les deux)

 

you need to have the equivalent of DIR_FS_CATALOG specified in this script as you use the FileSystem, and not the WebSite to find the file.

You are using filesystem cals, not opening urls in your script ...

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

An error in my error log file appears this is it :

 

syntax error, unexpected 'error_reporting' (T_STRING), expecting function (T_FUNCTION)

 

[Mon Aug 24 15:32:15 2015] [error] [client] PHP Parse error: syntax error, unexpected 'error_reporting' (T_STRING), expecting function (T_FUNCTION) in /var/www/clients/client1/web1/web/batchs/Classes/PHPExcel.php on line 1138 

 

la ligne en question c'est 

error_reporting(E_ALL);
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...