PDA

View Full Version : I need help in a simple upload script



darroosh
August 8th, 2008, 04:45 PM
please help me !

i tried this small script ...
but it doesn't work



This is th Html page :



<form action='up.php' method='post' enctype='multipart/form-data' >
<input type='file' name='fileup' size='20'>
<input type='submit' value='upload'>
</form>


And thi is the PHP page name up.php


<?
$fileup=$_POST['fileup'];
if($fileup == ""){
echo " please select a file ! ";
}else{
$path=$PHP_SELF;
$path .= "/files/$fileup_name";
$att = strrchr($fileup_name,'.');
$alemtdadat = array('.gif','.jpg','.jpgf','.zip','.rar');
$maxsize = "81920";
$file_size = filesize($fileup);
if(! in_array($att,$alemtdadat)){
echo " This extension isn't allowed !!";
}else if($file_size > $maxsize ){
echo " file size is larger than allowed ";
}else{
$CopyFile = copy($fileup,"$path");
if($CopyFile){
echo " file was uploaded succesfully : ";
echo "<a href='http://$HTTP_HOST/uploadfiles/files/$fileup_name'>http://$HTTP_HOST/uploadfiles/files/$fileup_name</a>";
}else{
echo " file was not uploaded ! ";
}
}
}
?>


always i get the msg : " please select a file !"

what is wrong with my script ???

actionAction
August 8th, 2008, 06:22 PM
It's because of this statement:


$fileup=$_POST['fileup'];//not a $_POST variable
if($fileup == ""){//this will always be true, because it is an uninitialized variable

Your code needs to reference the $_FILES superglobal array, not $_POST, like this:

if(isset($_FILES['fileup'])){//this checks if a file was uploaded
Please refer to this (http://www.tizag.com/phpT/fileupload.php) for more information.

darroosh
August 8th, 2008, 10:49 PM
Thank u very much ..

It's now working fine !

actionAction
August 8th, 2008, 10:52 PM
no problem darroosh! :)