File uploading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpdesigner
Forum Newbie
Posts: 5
Joined: Tue Apr 01, 2008 6:40 pm

File uploading

Post by phpdesigner »

HI my name is alaa Iam a beginner in the php language and Iam using wamp server. Please I have a question in file uploading first of all I went to my php.ini and made sure that the file uploading was on and made a directory c:/wamp/tmp
and then I went to the editor and wrote the following html

Code: Select all

 
<html>
<body>
<form method="POST" action="2.php" >
<b><i>Choose your file :
<input type="file" name="img1" size=20>
<br>
<input type="submit" value="Upload">
 
</body>
 
</html>
and I wrote a php code in the 2.php file and was :
<?php
if($_FILES[img1]!="")
{
    @copy($_FILES[img1][tmp_name],"c:/wamp/tmp".$_FILES[img1][name]) or die("Sorry");
}
else
{
    die("Sorrrrrry");
}
 
 
 
?>
<html>
<body>
The file size is <?$_FILES[img1][size]?>
</body>
 
</html>
and when I ran the programme and choose my file which Iwant to upload he always sent me the message Sorrrrrry so please I want to know what is wrong?????????
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: File uploading

Post by EverLearning »

You need enctype="multipart/form-data" in form tag:

Code: Select all

<form method="POST" action="2.php" enctype="multipart/form-data">
for $_FILES array to be populated.
phpdesigner
Forum Newbie
Posts: 5
Joined: Tue Apr 01, 2008 6:40 pm

Re: File uploading

Post by phpdesigner »

I wrote it but it is still not working and the file cannot be uploaded :banghead:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: File uploading

Post by JayBird »

You need to use move_uploaded_file(), not copy()

Also, please post in the correct forum and use the code tags to highlight your code on the forum.
phpdesigner
Forum Newbie
Posts: 5
Joined: Tue Apr 01, 2008 6:40 pm

Re: File uploading

Post by phpdesigner »

:D Thank you so much it finally worked in both functions

Code: Select all

@copy $ move_uploaded_file
and Iam realy so sorry because I posted this topic not in the correct forum :oops:
Post Reply