Page 1 of 1

File uploading

Posted: Tue Apr 01, 2008 7:01 pm
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?????????

Re: File uploading

Posted: Tue Apr 01, 2008 7:15 pm
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.

Re: File uploading

Posted: Wed Apr 02, 2008 2:30 am
by phpdesigner
I wrote it but it is still not working and the file cannot be uploaded :banghead:

Re: File uploading

Posted: Wed Apr 02, 2008 3:19 am
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.

Re: File uploading

Posted: Wed Apr 02, 2008 6:40 pm
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: