Page 1 of 1

why is this code not working? upload.

Posted: Mon Dec 18, 2006 2:00 am
by corillo181

Code: Select all

<?php
include_once'../includes/db.php';
//get variable
$d='../music/ap/';
$fme = $_FILES['ulfile']['name'];
$tmp= $_FILES['ulfile']['tmp_name'];
$type = $_FILES['ulfile']['type'];
$result=copy($tmp, $fpath);
$fpath=$d.$fme;
if(!$result){ 
echo " a problem occur";
}
?>

Posted: Mon Dec 18, 2006 2:38 am
by evilchris2003
Aside from asking you what errors your getting it would be useful when debugging to check if the variables are set correctly by using echo or print to show them on screen

Posted: Mon Dec 18, 2006 8:20 am
by feyd
Let's see...

Posted: Tue Dec 19, 2006 3:32 am
by corillo181
yeah but now is telling me i got the wrong type of file but i am uploaidng a jpeg type of image..

Code: Select all

<?php
if($_FILES['ulfile']['type']!='image/jpeg'){
echo "wrong type of photo file";
}else{
$pdir='../music/ap/';
$pname=$_FILES['ulfile']['name'];
$ptmp= $_FILES['ulfile']['tmp_name'];
$psize=$_FILES['ulfile']['size'];
$pos = strrpos($mname, '.');
$newname = $artist . substr($mname, $pos);
$ppath=$pdir.$newname;
$result=copy($ptmp, $ppath); 
if(!$result){
echo "problems";
exit();
}
}
?>

Posted: Tue Dec 19, 2006 7:40 am
by feyd
The type field is quite unreliable to verify the file being uploaded is what that entry says. The reason why is because the submitting agent supplies that information. PHP does not have the authority to verify that the type is what the agent says.

For images that PHP can understand, I always recommend getimagesize(), as it actually analyzes the headers in the file. This doesn't protected you entirely from bad files, but helps a lot.

For other file types, there is a thread referenced in Useful Posts that may be informative.

Posted: Tue Dec 19, 2006 10:35 am
by corillo181
the real problem was themname was named pname.

so i just had to change that.

thanx for the help.