View Full Version : Uploader not working?
loserWILL
05-06-2008, 12:31 AM
I'm just making a personal uploader out of a tutorial, and I keep getting a "file extension not alowed" error. I've tried a .psd and .png (they're both on the allowe dlist) yet it still gives me that. You can try yourself by going to: http://www.kolzy.com/upload/
Here's my code:
<?php
$path = "upload/";
$maxSize = "100000";
$maxWidth = "1500";
$maxHeight = "1500";
$allowedExt = ".gif,.bmp,.png,.jpg,.zip,.psd";
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?>
Slowpoke
05-06-2008, 12:41 AM
Hmm I got the same message -
"File extention not recognized.
Allowed extentions: .gif,.bmp,.png,.jpg,.zip,.psd"
Although I can't see anything wrong with the code (although I'm not an expert so there may be) sorry I wasn't much help. :(
chrisgocrazyH
05-06-2008, 12:52 AM
uhhm try this:
<?php
$path = "upload/";
$maxSize = "100000";
$maxWidth = "1500";
$maxHeight = "1500";
$allowedExt = ".gif, .bmp, .png, .jpg, .zip, .psd";
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?>
loserWILL
05-06-2008, 12:54 AM
That didn't work Chris, thanks boith of you.
chrisgocrazyH
05-06-2008, 01:38 AM
Then try getting rid of the "." with the extensions
loserWILL
05-06-2008, 02:06 AM
I've tried that already, it didn't work.
loserWILL
05-06-2008, 12:55 PM
Anybody?
Edited by Kaotix12 (Forum Moderator): Please do not double post in order to bump your thread.
loserWILL
05-06-2008, 08:42 PM
I really need help with this, does anybody know what's up with it? +rep to anyone who helps.
Edited by Kaotix12 (Forum Moderator): Please do not double post in order to bump your thread.
CoolHostUK-Dom
05-06-2008, 09:25 PM
try this:
<?php
$path = "uploads/";
$maxSize = "100000";
$maxWidth = "1500";
$maxHeight = "1500";
$allowedExt = array('jpg', 'gif', 'png', 'zip', 'psd');;
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?> Thanks ;)
kreechin
05-06-2008, 09:32 PM
at above, it would give this error;
File extention not recognized.
Allowed extentions: Array
Was the first thing i tried when i attempted to fix the code.
CoolHostUK-Dom
05-06-2008, 09:43 PM
#####################
your coding is a bit iffy
http://www.paintballfm.com/site/uploader.php << got that fixed, just saying The width of the image can only be: px regardless.
Tryyyy :) Thisss edited:
<?php
$path = "usr_pics_uploaded/";
$maxSize == "100000";
$maxWidth == "1500";
$maxHeight == "1500";
$allowedExt == array('jpg', 'gif', 'png', 'zip', 'psd');
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?>
loserWILL
05-06-2008, 10:56 PM
I get the following error: The width of the image can only be: px.
Then it doesn't even upload.
loserWILL
06-06-2008, 12:46 AM
I'm sure someone knows what's wrong with this, please.
Edited by Kaotix12 (Forum Moderator): Please do not double post in order to bump your thread.
Independent
06-06-2008, 01:46 PM
Try post it in the "Ask the coding community"
Jebbo
07-06-2008, 11:13 AM
Try this:
<?php
$path = "upload/";
$maxSize = "100000";
$maxWidth = "1500";
$maxHeight = "1500";
$allowedExt = ".gif,.bmp,.png,.jpg,.zip,.psd,.GIF,.BMP,.PNG,.JPG, .ZIP,.PSD";
function get_ext($file){
$ex = strstr($file,".");
return $ex;
}
if (!$_POST['submit']){
?>
<form method="post" action="" enctype="multipart/form-data">
<label>Select Image</label><br />
<input name="image_file" type="file"><br />
<input name="submit" type="submit" value="Upload">
</form>
<?php
}
else{
$file = $_FILES['image_file'];
if($file == NULL){
echo "No image selected.";
}else{
$random = rand(0,9999);
$random *= rand(0,9999);
$random *= rand(0,9999);
$random /= 3;
$file_name = $random."-".basename($_FILES['image_file']['name']);
$up_path = $path.$file_name;
$ext = get_ext($file);
list($width, $height, $ftype, $attr) = getimagesize($_FILES['image_file']['tmp_name']);
$fileExt = explode(",",$allowedExt);
if ($width > $maxWidth){
echo "The width of the image can only be: ".$maxWidth."px";
}elseif ($height > $maxHeight){
echo "The height of the image can only be: ".$maxHeight."px";
}elseif (!in_array($ext,$fileExt)){
echo "File extention not recognized.<br /> Allowed extentions: ".$allowedExt;
}else{
if(move_uploaded_file($file_name,$up_path)){
}else{
echo "Error with uploading the image.";
}
}
}
}
?>
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.