img upload and change name on submit

[code]

Document
<form action="act_upload.php" method="POST" enctype="multipart/form-data">
<input type="text" name="rename">
	<input type="file" name="file_img" >
	<input type="submit" name="submit" value="save">
</form>

<br><br>
<?php require("connect.php"); $query = mysql_query("Select * FROM upload"); while ($row = mysql_fetch_array($query)) { ?>

<img src="<?php echo $row["img_path"]; ?> " width=“200”>

<?php } ?>
[/code]

=================================================

[php]
require(‘connect.php’);

if(isset($_POST[‘submit’])){

$rename = $_POST['rename'];
$filetemp = $_FILES["file_img"]["tmp_name"];
$filename = $_FILES["file_img"]["name"];
$filetype = $_FILES["file_img"]["type"];

$filepath = "upload/".$filename;

move_uploaded_file($filetemp, $filepath);

$sql = mysql_query("INSERT INTO upload (img_name, img_path, img_type)
		VALUES ('$filename', '$filepath', '$filetype')");

}

header(‘location: upload.php’);
[/php]

Well, you did not post any text to explain what you need help with. Do you mean you wish to change the
name of the file when you save it or in the database? Help us to help you.

If you are talking about just the name itself, you need to remove the extension of the name and add it to the
new name. That is simple code. Your code pulls out the extension (type) and name from the $_FILES[] array.
Just rename it after that and save the new name instead.

Is this for a class project?

Sponsor our Newsletter | Privacy Policy | Terms of Service