Hi everyone, I have a simple bit of code to upload a file to the server, however I need this file to be renamed to a variable
e.g.
Name:
Upload: [Browse]
[submit]
when you submit, the file will upload and the name will be changed on the server to whatever was typed in the name field (not changing the extension obvo)
Name: tom
upload: 12.jpg [browse]
[submit]
----fileuploads----->
Server: tom.jpg
----------------------------------------------------------------#
This really is v urgent so any help anyone could give would be fantastic 🙂 Thanks v v v much!!!
this is the code I have atm....
<?php
/* Script name: uploadFile.php
* Description: Uploads a file via HTTP using a POST form.
*/
if(!isset($_POST['Upload']))
{
include("form_upload.inc");
} # endif
else
{
if($_FILES['pix']['tmp_name'] == "none")
{
echo "<B>File did not successfully upload. Check the file size. File must be less than 500k.</b><br>";
include("form_upload.inc");
exit();
}
if(!ereg("image",$_FILES['pix']['type']))
{
echo "<b> File is not a picture. Please try annother file.</b><br>";
include("form_upload.inc");
exit();
}
else
{
$destination = ''."".$_FILES['pix']['name'];
$temp_file = $_FILES['pix']['tmp_name'];
move_uploaded_file($temp_file,$destination);
echo "<p><b>The file has successfully upload:</B>
{$_FILES['pix']['name']}
({$_FILES['pix']['size']})</P>";
}
}
?>
and the inc file
<! -- program name: form_upload.inc
description: description: Displays a form to upload a file -->
<html>
<head>
<title>file upload</title>
</head>
<body>
<ol><li>upload<li>
<li>click upload</li>
<ol>
<div align="center"><hr>
<form enctype="multipart/form-data"
action="uploadFile.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<input type="file" name="pix" size="60">
<p>
<input type="submit" name="Upload" value="Upload Picture">
</form>
</body>
</html>