Forum Moderators: coopster
I guess my question is this; are there any settings in the php.ini file I should be looking for?
I have tried about 8 different php file upload scripts both on the server I am having trouble with, as well as a test server I have set up. All the scripts work on my demo server, but all fail on the new server.
That's what is leading me to believe there is some kind of php setting that I am overlooking or something.
As I said before I know the script works, I have used it multiple times, but here is the code in case someone sees something that I may be missing:
<?php
$uploadDir = '/path/to/my/new/directory/';
if(isset($_POST['upload']))
{
$planid=$_POST['planid'];
$title=$_POST['title'];
$position=$_POST['position'];
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePath = $uploadDir . $fileName;
$position=$_POST['position'];
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file ";
exit;
}
include '../library/config.php';
include '../library/opendb.php';
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO upload2 (planid, title, position, name, size, type, path ) ".
"VALUES ('$planid', '$title', '$position', '$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
include '../library/closedb.php';
echo "<br>Files uploaded<br>";
}
?>
Any help or further insight is hugely appreciated.
$uploadDir = '/path/to/my/new/directory/';
First on the list: verify the directory is writable. Check permissions there.
Second stop: paste this at the top of your script, but be SURE to remove it or comment it out before going live. To-the-screen error reporting is off by default on most servers as a security precaution.
error_reporting(E_ALL);
ini_set('display_errors', '1');
Nothing helpful? This means it's erroring before error_reporting can get to it. So . . . .
Third stop: error logs. If there's an error, it will show here. SSH in (or however you read error logs,) attempt an upload, then in your CLI immediately enter
tail /var/www/yourdomain.com/stats/wherever/your/error_log
This may give you a clue.
Last two things, probably not helpful but worth looking at: you can check your PHP versions, but I don't see anything there that would cause it to die in 4 or 5. The other is to make sure you're uploading files under 2MB, this is the default upload for PHP. If you need to upload larger files, you will have to tweak the system-wide .ini or add values to an .htaccess file in the directory of your scripts to increase max_upload_size, timeout values, and memory usage.
1. Yes, the file directory is writable. It is chmod'd to 777.
2. I added the following lines
error_reporting(E_ALL);
ini_set('display_errors', '1');
to the beginning of the script was still unable to see any error messages coming up.
3. So as you suggested, I ran the upload script the immediately SSH'd in to view the error log. Here is the error that I received:
(32)Broken pipe: client stopped connection before mmap completed
Any ideas on where to go from here?
So to anyone who has a similar problem and comes across ths post, check your ini file.
Thanks Rocknbil for your input though. Your suggestions did help me further narrow down the problem so that I knew what to discuss w/ my hosting provider.