uploading a file and changing its name
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
<?
if ($img1_name != "") {
$parts = pathinfo($img1);
@copy("$img1", "pictures/$new_name.$parts[extension]")
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>
if ($img1_name != "") {
$parts = pathinfo($img1);
@copy("$img1", "pictures/$new_name.$parts[extension]")
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>
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Try this
I've just added the '. bits to cover the variables
Code: Select all
<?
if ($img1_name != "") {
$parts = pathinfo($img1);
@copy("$img1", "pictures/'.$new_name.$parts[extension].'")
or die("Couldn't copy the file.");
} else {
die("No input file specified");
}
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Just do this instead. Don't bother with pathinfo()
Code: Select all
<?php
if ($img1_name != "") {
$parts = explode('.', $Img1);
array_reverse($parts);
@copy("$img1", "pictures/'.$new_name.$parts[0].'")
or die("Couldn't copy the file.");
} else {
die("No input file specified");
}
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia