Advertisement
Java_Volume1 Files #102910

Upload file, make name unique, save in MySql DB

This code will upload a file from a client computer to your server, give the file a new, unique name and save the new filename into a MySql database. It also checks the size of the file so you can give a maximum size for all files that will be uploaded.

AI

AI 요약: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

소스 코드
original-source
***upload.html***
<html>
<head>
</title></title>
</head>
<body>
<form name=form1 action=upload.php method=post enctype=multipart/form-data>
<input type=file name=FileToUpload>
<input type=hidden name=MaxFileSize value=64000>
</form>
</body>
</html>

***upload.php***
<?php
if ($FileToUpload_type == 'image/gif') {
$type = '.gif';
}
if ($FileToUpload_type == 'image/pjpeg') {
$type = '.jpg';
}
if ($FileToUpload_type == 'image/x-png') {
$type = '.jpg';
}
$newfile = substr($FileToUpload, -9);
if($FileToUpload_name = '') {
print("No file was selected!");
}
elseif($FileToUpload_size > $MaxFileSize) {
print("The file to upload is too big");
}
else {
$global_db = mysql_connect('localhost', 'User', 'Password');
mysql_select_db('DBName', $global_db) or die("Connection error");
$query = "INSERT INTO Filetable (File) VALUES ('$newfile$type')";
$result = mysql_query($query) or die("ERROR");
move_uploaded_file($FileToUpload, "/full/path/on/your/server/images/$newfile$type");
}
?>
원본 댓글 (3)
Wayback Machine에서 복구됨