|
|
|
rename file ตอนupload ..ผมต้องการที่จะ rename ไฟล์ให้เป็นแบบ จากไฟล์ชื่อปกติเปลี่ยนให้เป็น เลขid_วันเดือนปี |
|
|
|
|
|
|
|
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")){
$expFile = explode('.', $_FILES["fileUpload"]["name"]);
$fileType = $expFile[count($expFile)-1];
$filUpload = date('YmdHis').'.'.$fileType;
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
}
$insertSQL = sprintf("INSERT INTO as_computer (as_department, as_position, as_user, as_period, as_brand, as_sn, as_ram, as_hdd,as_purchase,filUpload,fileday,leftover,total,as_type,rq_status,as_time ) VALUES (%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s)",
GetSQLValueString($_POST['as_department'], "text"),
GetSQLValueString($_POST['as_position'], "date"),
GetSQLValueString($_POST['as_user'], "text"),
GetSQLValueString($_POST['as_period'], "text"),
GetSQLValueString($_POST['as_brand'], "text"),
GetSQLValueString($_POST['as_sn'], "text"),
GetSQLValueString($_POST['as_ram'], "text"),
GetSQLValueString($_POST['as_hdd'], "text"),
GetSQLValueString($_POST['as_purchase'], "text"),
GetSQLValueString($_FILES["filUpload"]["name"], "text"),
GetSQLValueString($_POST['fileday'], "text"),
GetSQLValueString($_POST['leftover'], "text"),
GetSQLValueString($_POST['total'], "text"),
GetSQLValueString($_POST['as_type'], "text"),
GetSQLValueString($_POST['rq_status'], "text"),
GetSQLValueString($_POST['as_time'], "text"));
Tag : PHP
|
|
|
|
|
|
Date :
2022-08-24 17:01:19 |
By :
lmgreen |
View :
545 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code
$expFile = explode('.', $_FILES["fileUpload"]["name"]);
$fileType = $expFile[count($expFile)-1];
$filUpload = date('YmdHis').'.'.$fileType;
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$filUpload))
{
$insertSQL = sprintf("INSERT INTO as_computer (as_department, as_position, as_user, as_period, as_brand, as_sn, as_ram, as_hdd,as_purchase,filUpload,fileday,leftover,total,as_type,rq_status,as_time ) VALUES (%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s,%s,%s,%s,%s)",
GetSQLValueString($_POST['as_department'], "text"),
GetSQLValueString($_POST['as_position'], "date"),
GetSQLValueString($_POST['as_user'], "text"),
GetSQLValueString($_POST['as_period'], "text"),
GetSQLValueString($_POST['as_brand'], "text"),
GetSQLValueString($_POST['as_sn'], "text"),
GetSQLValueString($_POST['as_ram'], "text"),
GetSQLValueString($_POST['as_hdd'], "text"),
GetSQLValueString($_POST['as_purchase'], "text"),
GetSQLValueString($_FILES["filUpload"]["name"], "text"),
GetSQLValueString($_POST['fileday'], "text"),
GetSQLValueString($_POST['leftover'], "text"),
GetSQLValueString($_POST['total'], "text"),
GetSQLValueString($_POST['as_type'], "text"),
GetSQLValueString($_POST['rq_status'], "text"),
GetSQLValueString($_POST['as_time'], "text"));
}
|
|
|
|
|
Date :
2022-08-24 23:58:54 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนด้วยครับ ขณะนี้เวลาอัพโหลดไฟล์ สามารถ Rename ได้เรียบร้อยแล้ว แต่ว่าใน Database Mysql ชื่อไฟล์ที่อัพโหลด ยังเป็นชื่อเดิมอยู่ ไม่ยอมเปลี่ยนตาม แก้ไขตรงส่วนไหนครับ
$ext=pathinfo (basename($_FIELES['filUpload']['name']),PATHINFO_EXTENSION);
$newimg= 'img_'.uniqid().".".$ext;
$image_path = "myfile/";
$upload_path = $image_path.$newimg;
move_uploaded_file($_FILES["filUpload"]["tmp_name"],$upload_path);
$filUpload = $newimg;
{
$insertSQL = sprintf("INSERT INTO as_computer (as_department, as_position, as_user, as_period, as_brand, as_sn, as_ram, as_hdd,as_purchase,filUpload,fileday,leftover,total,as_type,rq_status,as_time)
VALUES (%s,%s, %s, %s, %s, %s, %s, %s, %s, $filUpload, %s,%s,%s,%s,%s,%s)",
GetSQLValueString($_POST['as_department'], "text"),
GetSQLValueString($_POST['as_position'], "date"),
GetSQLValueString($_POST['as_user'], "text"),
GetSQLValueString($_POST['as_period'], "text"),
GetSQLValueString($_POST['as_brand'], "text"),
GetSQLValueString($_POST['as_sn'], "text"),
GetSQLValueString($_POST['as_ram'], "text"),
GetSQLValueString($_POST['as_hdd'], "text"),
GetSQLValueString($_POST['as_purchase'], "text"),
GetSQLValueString($_FILES['filUpload']["name"], "text"),
GetSQLValueString($_POST['fileday'], "text"),
GetSQLValueString($_POST['leftover'], "text"),
GetSQLValueString($_POST['total'], "text"),
GetSQLValueString($_POST['as_type'], "text"),
GetSQLValueString($_POST['rq_status'], "text"),
GetSQLValueString($_POST['as_time'], "text"));
}
|
|
|
|
|
Date :
2022-08-25 12:09:55 |
By :
lmgreen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code
$ext=pathinfo (basename($_FIELES['filUpload']['name']),PATHINFO_EXTENSION);
$newimg= 'img_'.uniqid().".".$ext;
$image_path = "myfile/";
$upload_path = $image_path.$newimg;
move_uploaded_file($_FILES["filUpload"]["tmp_name"],$upload_path);
$filUpload = $newimg;
{
$insertSQL = sprintf("INSERT INTO as_computer (as_department, as_position, as_user, as_period, as_brand, as_sn, as_ram, as_hdd,as_purchase,filUpload,fileday,leftover,total,as_type,rq_status,as_time)
VALUES (%s,%s, %s, %s, %s, %s, %s, %s, %s, $filUpload, %s,%s,%s,%s,%s,%s)",
GetSQLValueString($_POST['as_department'], "text"),
GetSQLValueString($_POST['as_position'], "date"),
GetSQLValueString($_POST['as_user'], "text"),
GetSQLValueString($_POST['as_period'], "text"),
GetSQLValueString($_POST['as_brand'], "text"),
GetSQLValueString($_POST['as_sn'], "text"),
GetSQLValueString($_POST['as_ram'], "text"),
GetSQLValueString($_POST['as_hdd'], "text"),
GetSQLValueString($_POST['as_purchase'], "text"),
GetSQLValueString($newimg, "text"),
GetSQLValueString($_POST['fileday'], "text"),
GetSQLValueString($_POST['leftover'], "text"),
GetSQLValueString($_POST['total'], "text"),
GetSQLValueString($_POST['as_type'], "text"),
GetSQLValueString($_POST['rq_status'], "text"),
GetSQLValueString($_POST['as_time'], "text"));
}
|
|
|
|
|
Date :
2022-08-27 10:44:15 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะครับ คุณ คนธรรมดา ไม่พิเศษ
ขณะนี้ทำได้แล้วครับ แต่อาจจะคนละวิธี แต่ก็ใกล้เคียงกันครับ
ส่วนวิธีของ
คุณ คนธรรมดา ไม่พิเศษ
สามารถนำไปประยุกต์ใช้กับการอัพเดทไฟล์ได้ครับ
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")){
$ext = pathinfo (basename($_FILES['filUpload']['name']), PATHINFO_EXTENSION);
$file_name = pathinfo (basename($_FILES['filUpload']['name']), PATHINFO_FILENAME);
if (strlen($file_name>0)) {
$newimg= 'img_'.uniqid().".".$ext;
}
$image_path = "myfile/";
$upload_path = $image_path.$newimg;
move_uploaded_file($_FILES['filUpload']['tmp_name'],$upload_path);
$filUpload = $newimg;
/*if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))*/
{
$insertSQL = sprintf("INSERT INTO as_computer (as_department, as_position, as_user, as_period, as_brand, as_sn, as_ram, as_hdd,as_purchase,filUpload,fileday,leftover,total,as_type,rq_status,as_time )
VALUES ('$as_department','$as_position','$as_user','$as_period','$as_brand','$as_sn','$as_ram','$as_hdd','$as_purchase','$filUpload','$fileday','$leftover','$total','$as_type','$rq_status','$as_time')",
GetSQLValueString($_POST['as_department'], "text"),
GetSQLValueString($_POST['as_position'], "date"),
GetSQLValueString($_POST['as_user'], "text"),
GetSQLValueString($_POST['as_period'], "text"),
GetSQLValueString($_POST['as_brand'], "text"),
GetSQLValueString($_POST['as_sn'], "text"),
GetSQLValueString($_POST['as_ram'], "text"),
GetSQLValueString($_POST['as_hdd'], "text"),
GetSQLValueString($_POST['as_purchase'], "text"),
GetSQLValueString($_FILES["filUpload"]["name"], "text"),
GetSQLValueString($_POST['fileday'], "text"),
GetSQLValueString($_POST['leftover'], "text"),
GetSQLValueString($_POST['total'], "text"),
GetSQLValueString($_POST['as_type'], "text"),
GetSQLValueString($_POST['rq_status'], "text"),
GetSQLValueString($_POST['as_time'], "text"));
}
|
|
|
|
|
Date :
2022-08-31 15:52:47 |
By :
lmgreen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|