Jump to content

photo uploader script nott working


altis88

Recommended Posts

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: jpg, jpeg, png, gif

 

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.