Sanatise CSV content in PHP -
i've built bulk user import engine web application , it's working perfectly. i'm sitting here asking myself, secure? after all, content of file being pumped database!
not being wisest security nerd around need little advice here.
- users not able rename file after it's uploaded.
- when file uploaded, name instantly changed.
- files must .csv , have csv relative mimetype upload work.
- the uploaded file stored in directory not accessible via www , deleted import has completed, few hundred milliseconds.
- i'm opening file , removing blank lines during import
what actual content of file? how can sanitize file ensure doesn't contain executable code? looked @ php manual , saw of php 4.3.5 getcsv() binary safe, being totally honest, i'm not 100% sure means.
i'm thinking converting csv content array , creating function escapes array content. other suggestions or above safe?
you can try using array_walk() run mysql_escape_string() or database's equivalent doubly sure kosher.
function escape_sql(&$item, $key) { $item = mysql_escape_string($item); } array_walk($input_array, 'escape_sql'); if array multi-dimensional can use array_walk_recursive(), operates similarly.
Comments
Post a Comment