uploading a file and changing its name
Posted: Mon Apr 19, 2004 6:19 pm
I was wondering if someone could help me, I am trying to upload a files but change the name of the file to what is typed into a textarea from another part of the page. I am new to php and just starting out. I have search the new for code like I am wanting but can't find just what I need.
This is the code I am working with.
***********************************************************
<HTML>
<HEAD>
<TITLE>Upload a File</TITLE>
</HEAD>
<BODY>
<H1> </H1>
<FORM METHOD="post" ACTION="do_upload.php" ENCTYPE="multipart/form-data">
<p> </p>
<p><b>New Name</b>:<input type="text" name="new_name" size="20"></p>
<p><strong>File to Upload:</strong><br>
<INPUT TYPE="file" NAME="img1" SIZE="30"></p>
<P><INPUT TYPE="submit" NAME="submit" VALUE="Upload File"></p>
</FORM>
</BODY>
</HTML>
**********************************************************
<?
if ($img1_name != "") {
@copy("$img1", "pictures/$img1_name")
or die("Couldn't copy the file.");
} else {
die("No input file specified");
}
?>
<HTML>
<HEAD>
<TITLE>Successful File Upload</TITLE>
</HEAD>
<BODY>
<H1>Success!</H1>
<P>You sent: <? echo "$img1_name"; ?>, a <? echo "$img1_size"; ?>
byte file with a mime type of <? echo "$img1_type"; ?>.</P>
</BODY>
</HTML>
This is the code I am working with.
***********************************************************
<HTML>
<HEAD>
<TITLE>Upload a File</TITLE>
</HEAD>
<BODY>
<H1> </H1>
<FORM METHOD="post" ACTION="do_upload.php" ENCTYPE="multipart/form-data">
<p> </p>
<p><b>New Name</b>:<input type="text" name="new_name" size="20"></p>
<p><strong>File to Upload:</strong><br>
<INPUT TYPE="file" NAME="img1" SIZE="30"></p>
<P><INPUT TYPE="submit" NAME="submit" VALUE="Upload File"></p>
</FORM>
</BODY>
</HTML>
**********************************************************
<?
if ($img1_name != "") {
@copy("$img1", "pictures/$img1_name")
or die("Couldn't copy the file.");
} else {
die("No input file specified");
}
?>
<HTML>
<HEAD>
<TITLE>Successful File Upload</TITLE>
</HEAD>
<BODY>
<H1>Success!</H1>
<P>You sent: <? echo "$img1_name"; ?>, a <? echo "$img1_size"; ?>
byte file with a mime type of <? echo "$img1_type"; ?>.</P>
</BODY>
</HTML>