Current location: Hot Scripts Forums » Programming Languages » PHP » Image Upload, File Type Check, File Size Check

Image Upload, File Type Check, File Size Check

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Question Image Upload, File Type Check, File Size Check

Hi,
I have a simple script i made to upload images, but my file size and file type check isn't working .

Heres my script:

PHP Code:

<title>Saving...</title>

<? 
/* Security Check */
$site $_GET['site'];
$pass $_GET['password'];
if (!
$pass)
echo
'<meta http-equiv="refresh" content="0;URL=index.php">';
else
require 
"$site/vars.php";
if (
$pass == "$password")
echo
"";
else 
exit();
/* Checked */


/* File Checking */
if ($_FILES['pic']['size'] > 5242880)
die(
'Too Big, Maximum Size is <strong> 5MB </strong>. <p> Please Wait As You Are Sent Back To The Change Photo Page... <meta http-equiv="refresh" content="3;URL=javascript: history.go(-1)">');

if (
$_FILES['pic']['type'] == "image/gif");
elseif (
$_FILES['pic']['type'] == "image/jpg");
elseif (
$_FILES['pic']['type'] == "image/jpeg");
elseif (
$_FILES['pic']['type'] == "image/bmp");
elseif (
$_FILES['pic']['type'] == "image/png");
else
die (
'<stong> Wrong </strong> Photo File Type, Must be: <strong> <p> Gif <p> Jpg <p> Jpeg <p> Bmp <p> Png </strong> <p> Please Wait As You Are Sent Back To The Change Photo Page... <meta http-equiv="refresh" content="4;URL=javascript: history.go(-1)">');
/* File Checked */

/* Delete Existing File */
if(file_exists("$site/$picl"))
unlink("$site/$picl");
else
echo
"";
/* Deleted*/

/* Uploading */
copy ($_FILES['pic']['tmp_name'], "$site/".$_FILES['pic']['name']);
/* Uploaded */


/* Vars For Writing */
$name $namel;
$pic $_FILES['pic']['name'];
$age $agel;
$location $locationl;
$gender $genderl;
$status $statusl;
$height $heightl;
$weight $weightl;
$job $jobl;
$about $aboutl;
$likes $likesl;
$hobbies $hobbiesl;
$contact $contactl;
$theme $themel;
$games $gamesl;
$counter $counterl;
$bg $bgl;
/* Vars Defined */

/* File Writing */
include"data-dex.php";
include
"data-vars.php";
/* File Written */

/* Confirmation */
include"successful.php";
/* Confirmed */
?>
Thanks
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Newbie Coder
 
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Check filesize: http://www.php.net/filesize
Check file type: http://www.php.net/manual/en/functio...ntent-type.php



If you need help:
PHP Code:

/* File Checking */

if (filesize($_FILES['pic']['size']) > 5242880)
die(
'Too Big, Maximum Size is <strong> 5MB </strong>. <p> Please Wait As You Are Sent Back To The Change Photo Page... <meta http-equiv="refresh" content="3;URL=javascript: history.go(-1)">');

if (
mime_content_type($_FILES['pic']['type']) == "image/gif");
elseif (
mime_content_type($_FILES['pic']['type']) == "image/jpg");
elseif (
mime_content_type($_FILES['pic']['type']) == "image/jpeg");
elseif (
mime_content_type($_FILES['pic']['type']) == "image/bmp");
elseif (
mime_content_type($_FILES['pic']['type']) == "image/png");
else
die (
'<stong> Wrong </strong> Photo File Type, Must be: <strong> <p> Gif <p> Jpg <p> Jpeg <p> Bmp <p> Png </strong> <p> Please Wait As You Are Sent Back To The Change Photo Page... <meta http-equiv="refresh" content="4;URL=javascript: history.go(-1)">');
/* File Checked */ 

Frank
Reply With Quote
  #3 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
thanks

thanks
Reply With Quote
  #4 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
:(

Thanks for the help but i get this error:

Warning: stat failed for 1907 (errno=2 - No such file or directory) in c:\ibserver\www\sites\save-image.php on line 18

Fatal error: Call to undefined function: mime_content_type() in c:\ibserver\www\sites\save-image.php on line 21

You can see for your self here:

http://217.42.225.48/Sites/edit-phot...254561b24f0ff5

Heres what my new script looks like:
PHP Code:

<title>Saving...</title>

<? 
/* Security Check */
$site $_GET['site'];
$pass $_GET['password'];
if (!
$pass)
echo
'<meta http-equiv="refresh" content="0;URL=index.php">';
else
require 
"$site/vars.php";
if (
$pass == "$password")
echo
"";
else 
exit();
/* Checked */


 /* File Checking */ 
if (filesize($_FILES['pic']['size']) > 5242880
die(
'Too Big, Maximum Size is <strong> 5MB </strong>. <p> Please Wait As You Are Sent Back To The Change Photo Page... <meta http-equiv="refresh" content="3;URL=java_script_: history.go(-1)">'); 

if (
mime_content_type($_FILES['pic']['type']) == "image/gif"); 
elseif (
mime_content_type($_FILES['pic']['type']) == "image/jpg"); 
elseif (
mime_content_type($_FILES['pic']['type']) == "image/jpeg"); 
elseif (
mime_content_type($_FILES['pic']['type']) == "image/bmp"); 
elseif (
mime_content_type($_FILES['pic']['type']) == "image/png"); 
else 
die (
'<stong> Wrong </strong> Photo File Type, Must be: <strong> <p> Gif <p> Jpg <p> Jpeg <p> Bmp <p> Png </strong> <p> Please Wait As You Are Sent Back To The Change Photo Page... <meta http-equiv="refresh" content="4;URL=java_script_: history.go(-1)">'); 
/* File Checked */ 


/* Delete Existing File */
if(file_exists("$site/$picl"))
unlink("$site/$picl");
else
echo
"";
/* Deleted*/

/* Uploading */
copy ($_FILES['pic']['tmp_name'], "$site/".$_FILES['pic']['name']);
/* Uploaded */


/* Vars For Writing */
$name $namel;
$pic $_FILES['pic']['name'];
$age $agel;
$location $locationl;
$gender $genderl;
$status $statusl;
$height $heightl;
$weight $weightl;
$job $jobl;
$about $aboutl;
$likes $likesl;
$hobbies $hobbiesl;
$contact $contactl;
$theme $themel;
$games $gamesl;
$counter $counterl;
$bg $bgl;
/* Vars Defined */

/* File Writing */
include"data-dex.php";
include
"data-vars.php";
/* File Written */

/* Confirmation */
include"successful.php";
/* Confirmed */
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
If statement in file upload mdhall PHP 4 04-12-04 05:33 PM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 08:30 PM
Image File Upload Script Millz PHP 6 12-30-03 10:37 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 08:50 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.