Hi there, here's a bit of code to get you started. It includes a form that
allows uploads, and the code to process the upload on the receiving page.
Basically, you have a form that allows an upload of a file on one page, and
some code on the receiving page to insert a path to that file in the
database and store the newly uploaded file in a directory on the webserver.
Of course you'll have to ensure that you have the proper write and read
permissions on that folder. There are a few 'print' lines sprinkled
throughout the code. For debugging you might want to un-comment them to see
how everything is working.

Hoe this helps you out!
Joe/Lerp :)


Here's a common form that allows you to upload a file (say an image or any
type of file for that matter) to the
db

<form action='upload.php' method='post' enctype='multipart/form-data'>
<input type='hidden' name='MAX_FILE_SIZE' value='25000'>
<P><font color='#ffffff' face='verdana' size=1>Upload Photo:</font><input
type='file' name='userfile'><input type='submit'
value='Upload!!!'></form></p>

################################end of upload form
##############################################################


############################start of upload process to db
################################################################
<?php


#$userfile is the file being uploaded




//print $userfile . "<BR>";
//print $userfile_name . "<BR>";

//determine file size -- if too big ( greater 50kb) then redirect
$siz = filesize($userfile);
//print $siz;

$ext = substr($userfile_name, -4);


// if the file not of type 'jpg' then redraw out upload form
if($ext != ".jpg"){
print "<font face='verdana' size='2' class='text_size_9'>The photo you
attempted to upload was of the wrong file type. Please ensure that the file
type is a 'jpg'.</font>";
print "<form method='POST' action='photoupload2.php'
enctype='multipart/form-data'><input type='file' name='userfile' size='15'
style='font-family: Verdana; font-size: 8pt;'><input type='submit' name='sub
mit' value='Upload' style='font-family: Verdana; font-size: 8pt;'>";
print "</form>";
print "</td></tr></table>";
print "<table width='470' cellspacing='10' cellpadding='10' border='0'>";
print "<tr><td height=30></td><td height=30></td></tr>";
print "<tr><td align=left><form name='forma' method=''
action='photos.php'><input type='submit' name='submit'
value='&laquo;&nbsp;Photos' style='background-color: #FFFFFF; font-family:
verdana; font-weight: bold; color: #363C70; font-size:
10pt;'></form></td><td></td></tr>";
print "</table></td>";
print "<td width='1' bgcolor='#FFFFFF' height='341'><img
src='images/pixel_transparent.gif' width='1' height='1' border='0'
alt=''></td>";
print "<td width='245' bgcolor='#363C70' align='center' valign='top'
height='341'>";
print "<table cellspacing='0' cellpadding='0' border='0'>";
print "<tr> <td></td></tr><tr>";
print "<td bgcolor='#FFFFFF'><img src='images/pixel_transparent.gif'
width='1' height='1' border='0' alt=''></td></tr></table>";
print "<table cellspacing='0' cellpadding='5' border='0'><tr>";
print "<td><img src='images/bullet_quick_tips_small.gif' width='17'
height='17' border='0' alt=''></td>";
print "<td><font face='verdana' size='1' class='text_size_8'> <a
href='contact.php' class='link_white_02'>Send us some
feedback!</a></font></td>";
print "</tr></table></td></tr></table>";

  exit;
}

if ($siz >= 51200){

//redraw upload form
print "<font face='verdana' size='2' class='text_size_9'>The photo you
attempted to upload was too large in file size. Please ensure that the file
size does not exceed 50kb.</font>";
print "<form method='POST' action='photoupload2.php'
enctype='multipart/form-data'><input type='file' name='userfile' size='15'
style='font-family: Verdana; font-size: 8pt;'><input type='submit'
name='submit' value='Upload' style='font-family: Verdana; font-size:
8pt;'>";
print "</form>";

}
elseif ($siz < 51200)
{

 $timestamp = time();
 $userfile_name = $timestamp.$userfile_name ;

 // copy the file being posted -- remember to escape backslashes!!!
 if(copy($userfile, "/ez/golfPHP/pics/". $userfile_name)){
 print "<font face='verdana' size='2' class='text_size_9'>Your photo has
been uploaded and is viewable in the photo gallery.</font><br><br>" ;
 }
 else
 {
 print "<font face='verdana' size='2' class='text_size_9'>A problem was
encountered during your photo upload.</font><br>";
 }

$patharola = "pics/". $userfile_name;
//print $patharola;

$caption = "No Caption.";

// insert path into database here
file://connect to db
$connectionToDBid = odbc_connect("golf", "joegolf", "joegolf");

//create query statement
$sqlr = "INSERT INTO PHOTO (golferid, photo, caption, datesubmitted) VALUES
('$sesgolferid' , '$patharola', '$caption', '$todaysdate' )";
//execute the sql statement (query) on the connection made
$resultset = odbc_do($connectionToDBid, $sqlr);

//grab the photoid from db
$sqlid = "SELECT @@IDENTITY AS NewId";
$napid = odbc_do($connectionToDBid, $sqlid);
$photoid = odbc_result($napid, 1);

//print "Photo Id is: " . $photoid . "<BR>";

// close the connection
odbc_close($connectionToDBid);



?>

################################end of insert to db process
##################################################








"Artisthotel" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> I need an upload script that lets predefined users log in and upload
files.
> Does such a script exist?
>
> Regards
> JEns
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to