dbase_open error on deleting rows from remote file - php

I hope you can help me with my problem.
I have a local site that reads data from DBF files on a terminal within the network. So what I did, I shared the DBF files on a PC running Windows XP, with full read/write permission.
When the PHP script is run on the Ubuntu server, it will first ping the PC on the network. After confirming that it is connected, it will mount the shared files within the server. Please note that the directory /mnt has 777 permissions and it is set to subdirectories as well. The owner is also www-data which is the user for PHP.
The script is able to read the data from the DBF files using this setup. I use the below script to read the data from the dbf file:
$db1 = dbase_open("/mnt/test.dbf", 0) or die(mysql_error());
for($counter=1;$counter<=dbase_numrecords($db1);$counter++){
$dbf_data = dbase_get_record_with_names($db1, $counter) or die(mysql_error());
// insert data to MYSQL database
}
The script above works, but only for reading the data. When I change to:
dbase_open("/mnt/test.dbf", 2)
it should have read and write access, However it does not let me remove the rows that were already read. I use:
for($count=1;$count<=dbase_numrecords($db1);$count++){
dbase_delete_record($db1, $count);
}
dbase_pack($db1);
but it doesnt work. I also tried to put dbase_pack inside the loop, but still the same. Here is a screenshot of the error:
Hope you can help. Thanks in advance!

Related

PHP connection to remote mysql with ssl works via command but not in browser

I want to connect to a remote (AWS) mysql server using ssl in PHP.
My script works when I execute it via command line, but doesn't when I call it from the browser.
$con=mysqli_init();
mysqli_ssl_set($con,NULL,NULL,"path/to/cacert.pem",NULL,NULL);
$link = mysqli_real_connect($con, "host", "username", "password");
I am using php7/Apache/CentOs. I tried changing the ownership and permissions of the CA file, and noticed that it requires read permission the be executed on console. But in browser even if I give full permission to everybody (chmod 777) it still doesn't work.
The error i get is:
Warning: failed loading cafile stream.
When I check existence of file it returns true, but when I check is_readible, then also error.
Can somebody help?Thanks!
So as I figured there was (is) something wrong with readability and maybe permissions. I could narrow down the problem to the certificate file being existent but not readable. I moved it to my server with filezilla via ftp.
I could solve my problem by creating a new .pem file and simply copying the content of my original file into it. This one is readable now and works in browser, but I can't figure out why as they both have the same chmod xxx permissions and chown ownership.
Detailed description(for users with similar problem using AWS MYSQL):
open rds-combined-ca-bundle.pem file(download link: https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem) in text editor.
Copy content.
On your server, where php script should run create new file and paste text into it.(it might require some additional editing, begin/end tags in separate line and new lines end at the same place as in original text)

How to execute xpdf (pdftotext.exe) on shared drive?

im trying to parse pdf to text via PHP and XPDF (pdftotext.exe). On my localhost everythings works well, but when im trying to move everything on server, im getting into troubles.
First of all i checked some settings on server and safe_mode is off, exec is not disabled and permissions are rwxrwxrwx.
Then im trying this
$command = "\\\\149.223.22.11\\cae\\04_Knowledge-base\\tools\\pdftotext.exe -enc UTF-8 ". $fileName . " \\\\149.223.22.11\\cae\\04_Knowledge-base\\output.txt";
$result = exec($command,$output,$args);
echo shell_exec($command);
which isnt working. When i look into $result, $output, are empty, but $args returns 1 which coresponds to Incorrect function by this document windows system error codes
Whole command looks like \\149.223.22.11\cae\04_Knowledge-base\tools\pdftotext.exe -enc UTF-8 \\149.223.22.11\cae\04_Knowledge-base\testpdf\04_egerland_final_paper.pdf \\149.223.22.11\cae\04_Knowledge-base\output.txt and when is dirrectly inputed into commandline, its working.
So im a bit out of ideas. Have someone any hint?
edit 20160201 - aditional trying
So i made aditional tests and when im trying to run similar command with exec from localhost (target .exe file, input and output file is in same location, only im using localhost not server) its working. Im now checking differences in server settings. So can here be problem, that localhosts Server Api is Apache 2.0 Handler and server is CGI/FASTCGI?
So it was all mistake on my side. I badly checked IIS permissions and forgot to assign user to virtual directory which i wana to access. So my only advice and more wisdom from this is to double (maybe triple) check if you have all permissions set correctly.

How to update/replace php script on server

I am working on update feature for a CMS. But I stuck on this. The scenario is user will able to upload a zip file, the updater script will extract it and replace the old one.
I have a problem with replacing, I've done the following
<?php rename($old, $new);
I always get "Permission Denied"
using ftp_rename:
<?php
$conn = ftp_connect($host);
ftp_login($conn, 'user', 'pass');
ftp_rename($conn, $src, $dest);
I always get
Warning: ftp_rename(): Rename Failed. on....
Is there a proper way to do this ? thanks.
Depending on your linux distro, php actually executes command as a specific user. Check your apache (or whatever server you are using) settings and put the permission accordingly
For example in apache, it is set
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
You can then change that upload folder to be owned by www-data
For more information you can read this useful discussion
https://unix.stackexchange.com/questions/30879/what-user-should-apache-and-php-be-running-as-what-permissions-should-var-www

Trouble with writing to file with php and my home server

So, I have this simple little php script. It runs and compiles fine and works the way I want it to on the machine that I coded it. I'm running it on a personal home web-server running Debian 6.0.6, 32bit. It's apache with php. And I know for a fact that php is working on the server.
<?php
$hitsfile = "hits.txt"; #name of file
$filehandle = fopen($hitsfile, 'r') or die ("Couldn't read file."); #Opens file, 'hitsfile' to be read.
$hits = fread($filehandle, 5); #reads file to the introduced variable, 'hits'
fclose($filehandle); #closes file
$hits++; #increments the variable that it read.
$filehandle = fopen($hitsfile, 'w') or die ("Couldn't write to file."); #opens file to be read.
fwrite($filehandle, $hits); #writes the hits variable to file.
fclose($filehandle); #closes file.
echo $hits; #outputs the hits variable.
?>
When I access the file from the server, via a web browser, I get the "Couldn't write to file." error. So then, it's opening the file properly, and reading it. And when it opens it to write, it fails. I'm assuming this is some sort of problem with permissions or something. I'm sort of at a loss as to how to solve the issue. Any ideas? Assistance would be greatly appreciated! I've googled for a couple days now, and I can't solve the issue. I'm a php 'noob' and I'm very new to running a linux-based web-server, but hey, you gotta learn somehow. :*l
tried to check the permissions to the file? The Linux file system have a very strict permission system. Write on terminal:
ls -la /path/to/my/file.txt
This would give you your permissions on the left column. Please read this article to be sure, and check if Apache have the "write" permissions to the file. If not, use the chmod command to give Apache access to the file (or the chown command, to change the owner of this file to apache, if the owner of this file have writing permissions).

FTP Mirroring with Codeigniter creates folder, but no files uploaded

I am using Codeigniter to backup mysql tables and write the sql file to the local webserver's htdocs/application/backups directory.
I want that directory to be mirrored on my remote webserver (dreamhost backups user account) but it's not working, I'm not seeing the sql files in the remote directory.
I'm using CI's FTP library and it's mirror() function to copy the contents of my local backups directory to my remote server.
In my database backup model I set variables to use in the scrip:
private $local_folder = 'my_directory/';
private $server_folder = 'my_server_directory/';
private $server_credentials = array(
'hostname'=>'my.hostname.com',
'username'=>'my_username',
'password'=>'my_password'
);
Also in the database backup model I have the mirror function:
function mirror(){
$this->load->library('ftp');
$this->ftp->connect($this->server_credentials);
$result = $this->ftp->mirror($this->local_folder,$this->server_folder);
var_dump($result); //shows "true"
$this->ftp->close();
}
I call the mirror() from my backup function. The sql files are created and stored locally by the backup function, but the local folder isn't mirrored to the webserver.
the remote backup directory permissions are '777' and test runs of $this->ftp->list_files and $this->ftp->mkdir() work just fine.
Any ideas why files won't be uploaded?
I'm posting an answer to my own question because the problem was my own ignorance.
private $server_folder = 'my_server_directory/';
should have been
private $server_folder = '/my_server_directory/';
I swear I tried that syntax while trouble shooting my problem, but I must have changed something else too that broke the mirroring at the same time, hiding the answer from me.
Thanks for your comments and answers #Damien Pirsy and # Edinho Almeida.
If
$this->ftp->mkdir()
works fine, I'm sure that your permission settings are ok.
If
$this->ftp->list_files()
works fine, I'm sure that your connection settings are ok too.
I guess your SQL backup files are starting with dot
See in
system/libraries/Ftp.php at lines 547 and 551

Categories