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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.