Author Topic: photo uploader script nott working  (Read 173 times)

0 Members and 1 Guest are viewing this topic.

Offline altis88Topic starter

  • Irregular
  • Posts: 1
    • View Profile
photo uploader script nott working
« on: March 18, 2010, 04:06:12 AM »
hey guys,

atm im working on my own site. the problem im having is that my photo uploader doesn't want to work. it's displaying the following error message:

 
this has no file extension that ends on
jpgjpegpnggif


the script:

<?php
if (isSet($_POST['new_submit'])){
	
// file info
	
$map "../gallery/photo";

	
$maxsize 400*1024;
	
$filetypes = array("jpg""jpeg""png""gif");
	

	
// function searches for file type
	
function 
search_extenstion($file){
	
	
$extenstion strtolower(substr(strrchr($file"."), 1));
	
	
return 
$extenstion;
	
}

	
$temporarily_file $_FILES['photo_file']['tmp_name'];
	
$name $map ."/"$_FILES['photo_file']['name'];
/*
	
//uitschakelen om lokaal te testen !!!!
	
if (!is_uploaded_file($_FILES['photo_file'])){
	
	
//$fout['lokaal_bestand'] = true;
	
	
//$foutmelding .= "het bestand werd niet opgeladen vanaf uw compute<br />r";
	
}
*/

	
if (!
stristr($_FILES['photo_file']['type'], "image")){
	
	
$msg_error .= "the file is not an image<br />";
	
}

	
if (
$_FILES['foto']['size'] > $maxsize){
	
	
$readable_size $maxsize 1024;
	
	
$msg_error .= "the file is larger than {$readable_size}kB<br />";
	
}

	
// <-- problem
	
$extensie search_extenstion($name);
	
if (!
in_array($extenstion$filetypes)){
	
	
$msg_error .= "this has no file extension that ends on: " implode(", "$filetypes);
	
}
	
if (!isSet(
$msg_error)){
	
	
copy($temporarily_file$name);
	
}
	
$content scandir($map);

	
foreach(
$content as $file){
	
	
$extensie strtolower(substr(strrchr($file"."), 1));
	
	
if (
in_array($extensie$filetypes)){
	
	
	
$list[] = $file;
	
	
}
	
}
}
?>
<?php
if (isSet($msg_error)) {
	
print 
$msg_error;
}
?>

Can you help me?

Offline ym_chaitu

  • Devotee
  • Posts: 652
  • Gender: Male
  • visit http://drvirusindia.com
    • View Profile
    • DrVirus
Re: photo uploader script nott working
« Reply #1 on: March 18, 2010, 04:31:55 AM »
r u trying this script in the Internet explorer??
if yes then u need to add some more extensions to your script..
pjpeg

also using ur script i think u r checking just the extension only, this is a wrong method of finding the file type..
u can do one more thing is that use this inbuilt function
mime_content_type


u can even try using this script

http://www.php.net/manual/en/features.file-upload.php#88959
« Last Edit: March 18, 2010, 04:37:04 AM by ym_chaitu »
Quote
Chaitanya Babu Yanamadala
http://drvirusindia.com
http://li8teesko.com

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: photo uploader script nott working
« Reply #2 on: March 18, 2010, 07:16:46 AM »
You are having a little trouble with your variable names in the following two lines of code -

$extensie search_extenstion($name);
if (!
in_array($extenstion$filetypes)){


If you were developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, php would help you by displaying all the errors it detects. You would save a TON of time. There would have been an undefined error message about the $extenstion variable (which is not spelled correctly anyway) since it is not the same variable name as what is being used in the line of code that is setting $extensie.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.