简体   繁体   中英

PHP file upload not working on CentOS6 but working on Apache2 on OSX 10.8

I have two simple scripts to upload a file from a particular path on a local machine and place it on an Apache server. It's working fine on Apache built into OSX 10.8 but not on CentOS 6. Here is the code:

http://mysite.mydomain.com/logsend.php?logfilename=logfile.log

Which then goes to "logsend.php":

<?php
$logfilename = $_GET['logfilename'];
$target_url = 'http://mysite.mydomain.com/logaccept.php';
$localdir = '/usr/local/mysoftware/logs/';
$logurl = $localdir . $logfilename;
$post = array('extra_info' => '123456','file_contents'=>'@'.$logurl);
    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
?>

This then goes to logaccept.php:

<?php
$uploaddir = realpath('uploads/') . '/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);
if (move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
    echo "Log file successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}
?>

The mac returns "Log file successfully uploaded" in the browser window as expected, but on the CentOS box I just get the PHP white screen of nothingness. Nothing shows up as an error in the Apache error_log and I'm stuck as to how to further troubleshoot this.

Any ideas? I attempted to load some debug code into the PHP files, but I still only get white space back:

ini_set('display_errors', 'On');
error_reporting(E_ALL);

I recently encountered a similar problem on a centOs machine. It turned out to be the selinux which is turned on by default in centOs. Make sure you have write permissions, and disable selinux. (or configure it to give your apache user access)

http://wiki.centos.org/HowTos/SELinux

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM