Re: File Upload within form

From: Date: Wed, 26 May 2004 18:46:27 +0000
Subject: Re: File Upload within form
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-187013@lists.php.net to get a copy of this message
"Tom Chubb" <tom@ps-hosting.co.uk> wrote in message news:JPEMIHJHEEGAJDFPLGHIGEIDEIAA.tom@ps-hosting.co.uk... > I am trying to design a custom form script and I've stumbled across a small > problem. > I want to implement a file upload into the form, but rather than posting to > another file I want to refresh the form and then show that there has been a > file uploaded. > > I know about changing the form action to: > <form action="<?php echo$_SERVER['PHP_SELF']; ?>" > method="post" name="form" > id="form"> > > But, what do I need to change to update the script? > I'm a newbie, but trying hard to learn! > > Thanks in advance for any help. > > Tom > > > <form action="upload.php" method="post" > ENCTYPE="multipart/form-data"> > <input type="file" size="60" name="spec"> > <!-- set the max file size --> > <input type="hidden" name="MAX_FILE_SIZE" value="500000"> > <input type="submit" value="upload"> > </form> > > > <?php > file://FILE UPLOAD SCRIPT > $file = $_POST[file]; > $path = "/relative/directory/to/file"; file://SET THIS TO THE RELATIVE PATH FROM > WHERE THE SCRIPT IS TO WHERE THE FILE SHOULD BE UPLOADED TO, > > if($file){ > print("File name: $file_name<P>/n"); > print("File size: $file_size bytes<P>/n"); This should be: if (isset($_FILES) && isset($_FILES['spec'])) { echo 'File name: ' . $_FILES['spec']['name'] . '<p>'; echo 'File size: ' . $_FILES['spec']['size'] . ' bytes<p>'; } > > if(copy($file, "$path/$filename")){ This should be: if (copy($_FILES['file']['tmp_name'], "$path/$filename")) { Regards, Torsten Roehr > print("Your File was uploaded successfully"); > } else{ > print("ERROR, your file was not successfully uploaded"); > } > unlink($file); > } > ?>

« previous php.general (#187013) next »