tags:

views:

41

answers:

3

I have three files:
1. moodsLogo.jpg
2. Copy of (images').jpg
3. Moods logo (Custom).jpg

and I have the following code:

// (..) some code here
$fileName     = valid_filename($_FILES[ 'Filedata' ][ 'name' ]);
$bl->updateFieldValue("tableName","columnName",$fileName, $id);

function valid_filename($filename)
{
    $filename = str_replace(" ", "_", $filename);
    $pattern = "/[^[a-z0-9._-]/";
    return preg_replace($pattern, "", strtolower($filename));
}

And the SQL looks like this:

  public function updateFieldValue($table,$column,$value, $id)
  {
    $result = parent::updateRow($table,$column, $value, $id);  
    return $result;
  }

  public function updateRow($table,$column, $value, $id)
  {
    $sql = "UPDATE $table SET $column = '$value' WHERE id = $id";
    $this->query($sql);
    return $this->query_result;    
  }

Now, processing file 1 and 2 works fine. In my DB I can see the entire filename with the extension.

But when I process file 3, the filename is either stored as moods_logo_custom.jp or moods_logo_custom.. I've even tried using 'Copy of (Custom).jpg' and it works fine.

An echo before calling the query, shows that $filename is correct.

So what on earth makes THAT specific filename fale ? Why can't I store the entire filename in DB?

A: 

Check you database schema to see if the field (referenced in you code as $column) on table $table is set to something like:

column_name VARCHAR(20)

Or possibly:

column_name CHAR(20)

You might need to ALTER the table(s) to allow for longer strings.

rjstelling
Bingo! It was CHAR(20) :-)
Steven
A: 

Hi Steven, Could it be the field length of the field you are storing the name in? The value moods_logo_custom.jp is 20 chars in length, or is this just coincidence?

Dave Rix
A: 

Here's a SQL command that will expand the width of your column to hold longer strings, because this seems to be the problem you're having.

ALTER TABLE __table__ MODIFY COLUMN __column__ VARCHAR(128) NOT NULL DEFAULT ""

Hope this works out for you!

Dan Loewenherz