Problem With Upload Script

Started on the old forum in June 2008 · view the original in the archive · old links redirect here

20 replies · 1,465 views · started 18 years ago · 1 min read

3 participants
Guest #21

firstly i created a simple upload script called upload.php, with the following code

<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.


<form action="getfile.php" method="post">

Type (or select) Filename: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />
<input type="submit" value="Upload File">
</form>

</body>
</html>

then i created a getfile script called getfile.php, with following code

<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php

if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], 
       "../uploads/{$_FILES['uploadFile'] ['name']}")  )
      {  print '

 The file has been successfully uploaded </p>';
       }
else
      { 
        switch ($_FILES['uploadFile'] ['error'])
         {  case 1:
                   print '

 The file is bigger than this PHP installation allows</p>';
                   break;
            case 2:
                   print '

 The file is bigger than this form allows</p>';
                   break;
            case 3:
                   print '

 Only part of the file was uploaded</p>';
                   break;
            case 4:
                   print '

 No file was uploaded</p>';
                   break;
         }
       }

?>
</body>
</html>

nothing happens, i tested it and nothing uploads!!!! whats the problem?

Ermm bro u have some syntax error in ur xhtml form.. That is when u use <form action="getfile.php" method="post"> only, the default value is taken for enctype attribute... default value of the enctype attribute is "application/x-www-form-urlencoded".

So wen ur using a form for file upload u have to change the enctype to "multipart/form-data"..

So above code should be changed as

<form action="getfile.php" method="post" enctype="multipart/form-data">

Try this and see... External image (may be gone)

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close