Jump to content

How to upload a file using a PHP script??

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
bishisht

bishisht

    Newbie

  • Members
  • PipPip
  • 23 posts
can anyone tell me how can I design a simple form through PHP that can upload pdf/doc file to a server using database along with the data submitted in the form?

#2
Digwnews

Digwnews

    Newbie

  • Members
  • Pip
  • 1 posts
What's the problem?

upload.php
<?php

if(!$_POST['go'])

{

echo '<form action=upload.php method=post enctype=multipart/form-data>

<input type=hidden name=go value=go>

<input type=file name=uploadfile>

<input type=submit value=Upload></form>';

}

else

{

copy($_FILES['uploadfile']['tmp_name'],"uploads/".basename($_FILES['uploadfile']['name']));

echo 'Uploaded!';

}

?>

File will be in "uploads" directory.

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
But it wasn't saving to file that was asked for...
but these two tutorials help you out good:
http://forum.codecal...-mysql-php.html
http://forum.codecal...our-images.html
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
bishisht

bishisht

    Newbie

  • Members
  • PipPip
  • 23 posts
copy($_FILES['uploadfile']['tmp_name'],"uploads/".basename($_FILES['uploadfile']['name']));


well m confused in this line. how the two variables uploadfile and tmp_name works?

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
uploadname is the name of the input tag in your html, tmp_name contains a randomized name of the file while temporary stored on the server to be handled by you.
you can try print_r($_FILES) and see how the array looks like and what info you can receive from the file upload process.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall