wrong filename in db after upload. Filename on server wrong also
wrong filename in db after upload. Filename on server wrong also
orionaselite
Posts: 49Questions: 13Answers: 4
<?php
ini_set('session.save_path', '/tmp');
date_default_timezone_set('Europe/Athens');
session_start();
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
function logChange ( $db, $action, $id, $values ) {
//var_dump($_SESSION);
$username = $_SESSION['username'];
$desc = 'Admin with email '.$username.' has taken action '.$action.' using values '.json_encode( $values ).' on table ads in row '.$id;
$db->insert( 'logs', array(
'user_id' => $_SESSION['id'],
'description' => $desc,
'log_date' => date('c')
) );
}
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'ads', 'id' )
->fields(
Field::inst( 'banner_image' )
->setFormatter( 'Format::nullEmpty' )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/mobile_app_data/upload/__ID__.__EXTN__' )
//->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/ael-futsal-new/upload/ad_pics/__ID__.__EXTN__' )
//->upload(Upload::inst( function ( $file, $id ) {
//move_uploaded_file( $file['tmp_name'], '../mobile_app_data/upload/ad_pics/'.$id.'.__EXTN__');
// move_uploaded_file($file['tmp_name'], '../mobile_app_data/upload/ad_pics/__ID__.__EXTN');
// return '__ID__.__EXTN__';
//} )
->db( 'ads_images', 'id', array(
'filename' => Upload::DB_FILE_NAME
) )
->allowedExtensions( [ 'png', 'jpg', 'gif' ], "Παρακαλώ η εικόνα να είναι μορφής .jpg ή png ή .gif" )
),
Field::inst( 'created_date' )
->validator( 'Validate::notEmpty' )
->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d H:i:s' ) )
->getFormatter( 'Format::datetime', array( 'from'=>'Y-m-d H:i:s', 'to' =>'Y-m-d H:i:s' ) )
->setFormatter( 'Format::datetime', array( 'to' =>'Y-m-d H:i:s', 'from'=>'Y-m-d H:i:s' ) ),
Field::inst( 'updated_date' )
->validator( 'Validate::notEmpty' )
->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d H:i:s' ) )
->getFormatter( 'Format::datetime', array( 'from'=>'Y-m-d H:i:s', 'to' =>'Y-m-d H:i:s' ) )
->setFormatter( 'Format::datetime', array( 'to' =>'Y-m-d H:i:s', 'from'=>'Y-m-d H:i:s' ) ),
Field::inst( 'screen_position' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'status' )
->validator( 'Validate::notEmpty' )
)
->on( 'postCreate', function ( $editor, $id, $values, $row ) {
logChange( $editor->db(), 'create', $id, $values );
} )
->on( 'postEdit', function ( $editor, $id, $values, $row ) {
logChange( $editor->db(), 'edit', $id, $values );
} )
->on( 'postRemove', function ( $editor, $id, $values ) {
logChange( $editor->db(), 'delete', $id, $values );
} )
->on( 'preCreate', function ( $editor, $values ) {
$editor
->field( 'created_date' )
->setValue(date('Y-m-d H:i:s'));
} )
->on( 'preEdit', function ( $editor, $values ) {
$editor
->field( 'updated_date' )
->setValue(date('Y-m-d H:i:s'));
} )
->where( 'status', 2, '!=' )
->process( $_POST )
->json();
Why do I get 13.EXTN for example instead 13.png or 13.tiff or whatever??
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Fixed using
Please kindly consider the question answered