Jump to content

Upload and Rename


Chicken

Recommended Posts

I'm trying to upload and rename some files, renaming them by the form used to upload them (a hidden input). So far I've gotten the uploading to work but I'm a little confused as how to rename the uploaded file. This is what I have so far:

 

My submit form

<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" />
<input type="hidden" name="name" value="00000" /> <br>
<input type="submit" value="Upload" />
</form>
</body>
</html>

 

My upload.php

<?php
$target = "uploads/";
$target = $target . basename( $_FILES['uploaded']['name']) ;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file was uploaded";
}
else
{
echo "Problem during upload";
}
?>

 

I am not concerned about file size, or anything like that, and the file types are all txt

Link to comment
https://forums.phpfreaks.com/topic/71131-upload-and-rename/
Share on other sites

eh, I'm getting an error still this is what my new upload.php looks like:

<?php
$name = $_REQUEST["name"];
$target = "uploads/";
$target = $target . $name;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file was uploaded";
}
else
{
echo "Problem during upload";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/71131-upload-and-rename/#findComment-357865
Share on other sites

Take a look at this tutorial

http://php.about.com/od/advancedphp/ss/rename_upload.htm

 

It shows you exactly how to do it. Google brings up a lot of different tutorials, so you might want to try that if the tut I gave you doesn't work.

Link to comment
https://forums.phpfreaks.com/topic/71131-upload-and-rename/#findComment-358192
Share on other sites

Hello,

 

What is the value of $target you are getting. Since the following code is running successfully on my end..

 

<?php
// new name for the uploaded file test.jpg
$name = 'test1.jpg';
$target = "uploads/";
$target = $target . $name;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file was uploaded";
}
else
{
echo "Problem during upload";
}
?> 

 

Regards,

Link to comment
https://forums.phpfreaks.com/topic/71131-upload-and-rename/#findComment-358958
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.