Re: Uploading Files with PHP
| From: | Lerp | Date: | Fri, 22 Feb 2002 17:04:42 +0000 |
| Subject: | Re: Uploading Files with PHP | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-85863@lists.php.net to get a copy of this message | ||
Hi Jim, here's how I do it. I test for the file size on the processing page
as well, if it's too large I redraw out the upload form.
//test for file extension type if needed
//determine file size -- if too big ( greater 50kb) then redirect
$siz = filesize($userfile);
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='photoupload.php'
enctype='multipart/form-data'><input type='hidden'
name='MAX_FILE_SIZE'
value='51200'>
<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
if(copy($userfile, "/dir/dir/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;
//connect to db
$connectionToDBid = odbc_connect("dgsff", "sdgsdfg", "sdfgsdfg");
//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);
blah blah blah ...
Hope this helps you out, Joe :)
"Jim Koutoumis" <jimk@tcsman.com.au> wrote in message
news:20020221224805.43972.qmail@pb1.pair.com...
> Joe,
>
> Do you know when the file size is checked ??
>
> I think it only gets checked after the form is posted and file uploading
is
> finished ??
>
> I don't know how it's possible to catch things before user uploads - now
> that would be neat :-)
>
> Jim.....
>
> "Lerp" <joe@coastaldestination.com> wrote in message
> news:20020221201447.55691.qmail@pb1.pair.com...
> > Hi there :) Did you set a max file size in your upload form? See my form
> > below, notice the 'MAX_FILE_SIZE' value='102400' part within hidden
field.
> > This should appear before the rest of the form. You can adjust this
value
> as
> > you wish.
> >
> >
> > <form action='resumeupload.php' method='post'
> enctype='multipart/form-data'>
> > <input type='hidden' name='MAX_FILE_SIZE'
value='102400'>
> > <font color='#663399' face='verdana'
> > size=2><b>Upload
> > Resume:</b></font>
> > <input type='file' name='userfile'
> style='background-color:
> > #FFFFFF; font-family: verdana; font-weight: bold; color: #9999FF;
> font-size:
> > 9pt;'>
> > <input type='submit' value='Upload!!!'
> > style='background-color: #FFFFFF; font-family: verdana; font-weight:
bold;
> > color: #9999FF; font-size: 9pt;' name="submit">
> > </form>
> >
> >
> > Hope this helps, Joe :)
> >
> >
> >
> > "Chuck "Pup" Payne" <cepayne@magidesign.com> wrote in message
> > news:B89AB813.977D%cepayne@magidesign.com...
> > > Hi,
> > >
> > > I am trying to set a small script that would let my clients upload
file
> > with
> > > a Explorer or Netscape, but the problem is it would let me upload any
> file
> > > that is great than a 1MB. We get an error that the file "none" could
not
> > be
> > > read.
> > >
> > > I have set the upload_tmp_dir=/tempupload is has been chmod to 777,
> > php.ini
> > > as been set to 20MB, I know that is a lot but we are engingeering
> company
> > > that work with CADD files.
> > >
> > > Any clues where to look? The PHP 4 Bible from IDG states that we have
to
> > > under HTTP uploads, but nothing else. Is there some where on the net
> that
> > > explains better what I have to set up, turn on, or haven't done?
> > >
> > > Thanks,
> > >
> > > Chuck
> > >
> >
> >
>
>