3

I've been working on a custom cms and I'm having trouble creating a form where a user can update the thumbnail associated with a given row. I have another page where they can do the initial upload, and it all works perfectly, but for some reason, even after copy and pasting the code directly to the update page, php returns errors for the following two lines:

move_uploaded_file($_FILES['thumbnail']['tmp_name'], "images/" . $_FILES['thumbnail']['name']);
$thumbnail_location = 'images/'. $_FILES['thumbnail']['name'];

The page leading to this one just contains a normal form where the upload input has a name of "thumbnail". Here is a little more of the related code although it does not seem to be the problem.

move_uploaded_file($_FILES['thumbnail']['tmp_name'], "images/" . $_FILES['thumbnail']['name']);
$thumbnail_location = 'images/'. $_FILES['thumbnail']['name'];
$id = $_GET['id'];



    $workset = mysql_query('SELECT * FROM work WHERE id='.$id.' LIMIT 1', $connection);
    while ($work = mysql_fetch_array($workset)) {

        mysql_query('UPDATE work SET thumbnail="'.$thumbnail_location.'" WHERE id='.$id.'');
    }

2 Answers 2

3

you must add enctype="multipart/form-data" to your form :

<form method="post" action="" enctype="multipart/form-data">  
Sign up to request clarification or add additional context in comments.

3 Comments

Wow. I spent hours on this. Thank you so much.
@RobForrest: The 15 minute restriction has not yet elapsed.
It's still good that he told me. I'm new so I wouldn't have done it otherwise. :)
0

@mgrahy that's true well done. just here am trying to do the complete html form @tom c

<form method="post" action="" enctype="multipart/form-data">  
<input type ="thumbnail[]" multiple>
<input type ="submit" value="uplod">
</form>

1 Comment

thats gud 2 althogh mgraph provided close to similar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.