PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old February 23rd, 2013, 10:44 AM
The Wizard The Wizard is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 The Wizard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 2 sec
Reputation Power: 0
Image Uploader error problem

Hello:

Below is a image uploader script I am working on. I can't seem to get the error system to work right. When I bench test it with a file that is bigger then the max file size it lets the image through and the error message does not show up. Anybody got any ideas on what I'm doing wrong and how to fix it.

Thanks

Wiz


Code:
<?php

    //define a maxim size for the uploaded images in Kb
    define ("MAX_SIZE","100"); 

    //checks if the form has been submitted
    if(isset($_POST['Submit'])) 
    {
 	//reads the name of the file the user submitted for uploading
 	$image=$_FILES['image']['name'];
	
	//get the extension of the file in a lower case format
  	$extension = getExtension($image);
 	$extension = strtolower($extension);
    }
  
    if(isset($_POST['Submit']) && ($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
    {
    //print error message
 	echo '<h1>Unknown file extension!</h1>';
	echo '<h1>Copy unsuccessfull!</h1>';
 	exit;
    }
	
	//get the size of the image in bytes
	$size=filesize($_FILES['file']['size']);
	
	if(isset($_POST['Submit']) && ($size > MAX_SIZE/1024))
    {
	echo '<h1>You have exceeded the size limit!</h1>';
	echo '<h1>Copy unsuccessfull!</h1>';
	exit;
    }

	//the new name will be containing the full path where will be stored (images folder)
    $newname="images/".$image;
	
	//If no errors registred, upload and print the success message
    if(isset($_POST['Submit'])) 
    {
    copy($_FILES['image']['tmp_name'], $newname);
 	echo "<h1>File Uploaded Successfully! Try again!</h1>";
    }
		
?>

<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
 	<tr><td><input type="file" name="image"></td></tr>
 	<tr><td><input name="Submit" type="submit" value="Upload image">
        </td></tr>
</table>	
</form>

Reply With Quote
Old February 25th, 2013, 11:27 PM
Strider64 Strider64 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 Strider64 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 55 sec
Reputation Power: 0
Hope this helps.....
PHP Code:
if (isset($_POST['submit'])) { 
 
// USER Presses submit button
       
$allowedExts = array("jpg""jpeg""gif""png");
       
$basenameAndExtension explode('.'$_FILES["file"]["name"]);
       
$extension end($basenameAndExtension);
    
       if (((
$_FILES["file"]["type"] == "image/gif")
       || (
$_FILES["file"]["type"] == "image/jpeg")
       || (
$_FILES["file"]["type"] == "image/png")
       || (
$_FILES["file"]["type"] == "image/pjpeg"))
       && (
$_FILES["file"]["size"] < 800000)
       && 
in_array($extension$allowedExts))
        {
        if (
$_FILES["file"]["error"] > 0)
          {
          echo 
"Return Code: " $_FILES["file"]["error"] . "<br>";
          }
        else
          {
          echo 
"Upload: " $_FILES["file"]["name"] . "<br>";
          echo 
"Type: " $_FILES["file"]["type"] . "<br>";
          echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
          echo 
"Temp file: " $_FILES["file"]["tmp_name"] . "<br>"

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Image Uploader error problem


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap