Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP > ASP Forum > สำคัญจริงๆครับ ขอความช่วยเหลือหน่อยครับ เพื่อไม่ให้เสียเวลา ผมขอเริ่มเลยแล้วกันนะครับ... ในการอัพโหลด



 

สำคัญจริงๆครับ ขอความช่วยเหลือหน่อยครับ เพื่อไม่ให้เสียเวลา ผมขอเริ่มเลยแล้วกันนะครับ... ในการอัพโหลด

 



Topic : 003358

Guest




เพื่อไม่ให้เสียเวลา ผมขอเริ่มเลยแล้วกันนะครับ...

ในการอัพโหลด ถ้าต้องการให้ รหัสสมาชิก เป็นชื่อไฟล์ของไฟล์ที่สมาชิกอัพโหลด แล้วเก็บชื่อไฟล์เข้าฐานข้อมูล จะมีวิธี่อย่างไรในการทำครับ

ผมอัพโหลดได้แล้ว แต่ไม่สามารถแก้ไขชื่อไฟล์ที่อัพโหลด ให้เป็นรหัสสมาชิก ครับ

ช่วยแนะนำหน่อยนะครับ


Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 21 มี.ค. 2548 01:52:05 By : NimKab View : 2512 Reply : 3
 

 

No. 1

Guest


ผม ไม่แน่ใจนะฮะ ลองดูละกันเผื่อ ช่วยได้บ้าง
ผมมี Class upload file ซึ่งมี Function save_file($path, $mode) ซึ่งผมจะเพิ่ม parameter เป็น save_file($path, $mode , $fileNameUser) ซึ่ง fileNameUser เกิดจากการ รหัสสมาชิก นะฮะ

//************************************************************************************************************
<?
/*
Error codes:
0 - "No file was uploaded"
1 - "Maximum file size exceeded"
2 - "Maximum image size exceeded"
3 - "Only specified file type may be uploaded"
4 - "File already exists" (save only)
*/

class uploader {

var $file;
var $errors;
var $accepted;
var $new_file;
var $new_file2;
var $max_filesize;
var $max_image_width;
var $max_image_height;

function max_filesize($size){
$this->max_filesize = $size;
}

function max_image_size($width, $height){
$this->max_image_width = $width;
$this->max_image_height = $height;
}

function upload($filename, $accept_type, $extention) {
// get all the properties of the file

$index = array("file", "name", "size", "type");
for($i = 0; $i < 4; $i++) {
$file_var = '$' . $filename . (($index[$i] != "file") ? "_" . $index[$i] : "");
eval('global ' . $file_var . ';');
eval('$this->file[$index[$i]] = ' . $file_var . ';');
}

if($this->file["file"] && $this->file["file"] != "none") {
//test max size
if($this->max_filesize && $this->file["size"] > $this->max_filesize) {
$this->errors[1] = "Maximum file size exceeded. File may be no larger than " . $this->max_filesize/1000 . "KB.";
return False;
}
if(ereg("image", $this->file["type"])) {
$image = getimagesize($this->file["file"]);
$this->file["width"] = $image[0];
$this->file["height"] = $image[1];

// test max image size
if(($this->max_image_width || $this->max_image_height) && (($this->file["width"] > $this->max_image_width) || ($this->file["height"] > $this->max_image_height))) {
$this->errors[2] = "Maximum image size exceeded. Image may be no more than " . $this->max_image_width . " x " . $this->max_image_height . " pixels";
return False;
}
switch($image[2]) {
case 1:
$this->file["extention"] = ".gif";
break;
case 2:
$this->file["extention"] = ".jpg";
break;
case 3:
$this->file["extention"] = ".png";
break;
default:
$this->file["extention"] = $extention;
break;
}
}
else if(!ereg("(\.)([a-z0-9]{3,5})$", $this->file["name"]) && !$extention) {
// add new mime types here
switch($this->file["type"]) {
case "text/plain":
$this->file["extention"] = ".txt";
break;
default:
break;
}
}
else {
$this->file["extention"] = $extention;
}

// check to see if the file is of type specified
if($accept_type) {
if(ereg($accept_type, $this->file["type"])) { $this->accepted = True; }
else { $this->errors[3] = "Only " . ereg_replace("\|", " or ", $accept_type) . " files may be uploaded"; }
}
else { $this->accepted = True; }
}
else { $this->errors[0] = ""; }
return $this->accepted;
}

//function save_file($path, $mode){ // ปกติจะใช้คำสั่งนี้ ฮะ
function save_file($path, $mode , $fileNameUser) {
global $NEW_NAME;
// echo "<br>inside save_file function (path, mode) $path , $mode";
if($this->accepted) {
// very strict naming of file.. only lowercase letters, numbers and underscores
//$new_name = ereg_replace("[^a-z0-9._]", "", ereg_replace(" ", "_", ereg_replace("%20", "_", strtolower($this->file["name"])))); ปกติจะใช้คำสั่งนี้ ฮะ
$new_name = $fileNameUser ; // เพิ่มใหม่สำหรับ รหัสสมาชิก


// check for extention and remove
if(ereg("(\.)([a-z0-9]{3,5})$", $new_name)) {
$pos = strrpos($new_name, ".");
if(!$this->file["extention"]) { $this->file["extention"] = substr($new_name, $pos, strlen($new_name)); }
$new_name = substr($new_name, 0, $pos);

}
$this->new_file = $path . $new_name . $this->file["extention"] ;
$NEW_NAME = $new_name . $this->file["extention"] ;

switch($mode) {
case 1: // overwrite mode
$aok = copy($this->file["file"], $this->new_file);
break;
case 2: // create new with incremental extention
while(file_exists($path . $new_name . $copy . $this->file["extention"])) {
$copy = "_copy" . $n;
$n++;
}
$this->new_file = $path . $new_name . $copy . $this->file["extention"];
$this->new_file2 = $new_name . $copy . $this->file["extention"];

// echo "<br>inside save_file function file1 ->". $this->file["file"] ." file2 ->".$this->new_file ;

$aok = copy($this->file["file"], $this->new_file);
break;
case 3: // do nothing if exists, highest protection
if(file_exists($this->new_file)){
$this->errors[4] = "File &quot" . $this->new_file . "&quot already exists";
}
else {
$aok = rename($this->file["file"], $this->new_file);
}
break;
default:
break;
}
if(!$aok) { unset($this->new_file); }
return $aok;
}
}
}
?>



//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

วิธีเรียกใช้ฮะ

if ( ( is_null($userfile1) === FALSE ) and ( $userfile1 !== "" ) ){
$PATH ="images/" ;
$FILENAME = "userfile1" ;
$SAVE_MODE = 2;
$userfile="userfile1" ;

$upload = new uploader;
$upload->max_filesize(1000000);

if( $upload->upload("$FILENAME", "$ACCEPT", "$EXTENSION") ) {
// if($upload->save_file( "$PATH", $SAVE_MODE)) { ปกติ จะใช้คำสั่งนี้ฮะ
if($upload->save_file( "$PATH", $SAVE_MODE , $memberCode )) {


print("<center><p>Saved as: $pathThum/" . $upload->new_file . "<p>");
print_file($upload->new_file, $upload->file["type"], 2);
echo "<br>Finish Upload!!";









Date : 21 มี.ค. 2548 10:38:59 By : bobo
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ขอ code ในส่วนของการ save รูปหน่อยนะครับ ทำไมถึงเปลี่ยนชื่อไม่ได้
Date : 21 มี.ค. 2548 18:17:24 By : @W_IN
 

 

No. 3

Guest


โค๊ดก็เอามาจากเว็บนี้ทั้งดุ้นเลยครับ แก้ไขนิดหน่อยแล้วเอาชื่อลงฐานข้อมูลเวลาเก็บก็เก็บทั้งชื่อและนามสกุล

แต่ต้องการเปลี่ยนชื่อของไฟล์ที่อัพโหลดเป็นรัหสของผู้ส่งเท่านั้น
Date : 21 มี.ค. 2548 22:53:15 By : NimKab
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สำคัญจริงๆครับ ขอความช่วยเหลือหน่อยครับ เพื่อไม่ให้เสียเวลา ผมขอเริ่มเลยแล้วกันนะครับ... ในการอัพโหลด
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่