why is this code not working? upload.

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
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

why is this code not working? upload.

Post 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";
}
?>
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Let's see...
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post 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();
}
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

the real problem was themname was named pname.

so i just had to change that.

thanx for the help.
Post Reply