Current location: Hot Scripts Forums » Programming Languages » PHP » image upload getfilesize


image upload getfilesize

Reply
  #1 (permalink)  
Old 03-30-08, 12:30 PM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
image upload getfilesize

I don't know if this will be the best place to post this since it may be client side I am after.

I am trying to find a way of getting the file information e.g. size, dimensions from an image file before uploading to the server.

The only thing I have come across that seems to do this is uber upload but it is a bit too much overkill (too many features). Surely there is a simple way of getting the files attached information to post to my php script before it starts uploading the image.

Reason being, I don't want people to accidentally upload an image that is too large, wait a few minutes only to get the "file too large" message at the end. I want them to get the message before the image starts uploading. Input field max_file_size doesn't work anymore.

Does anyone know what part of uber upload is responsible for getting the filesize info when you click on upload? Is it php, java, javascript???
__________________
Aye!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-30-08, 12:49 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
You're right, it is client side not server side (php). I'm guessing there will be a way with either a java applet or java script, although I'm not 100%

Take a look here for upload applets
http://www.hotscripts.com/Java/Apple...ent/index.html
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName

Last edited by Jay6390; 03-30-08 at 01:05 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-30-08, 05:20 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
If you're certain the file is an image then you can check image sizes (not file sizes). Some untested javascript code I found via Teh Google:

Code:
var imOK = false;
var im

function fromOnChange() {
  im = new Image();
  im.src = document.myForm.myFile.value;
  imOK = false;
  im.onload=checkSize
  im.onerror=imError
}

function imError() {
  imOK = false;  
}

function checkSize() {
  if(im) {
       if(im.width < 100 ) {
          if(im.height < 100 ) {
             imOK = true;
             return;
          }
       }
  }
  imOK = false;
}
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-30-08, 06:18 PM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for that. But since it's javascript, how do I integrate that into my script?
__________________
Aye!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-30-08, 06:37 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by Deansatch View Post
Thanks for that. But since it's javascript, how do I integrate that into my script?
I don't know, I can't see your script from here. If you would post your script so we could see it then we'll have a look.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 03-30-08 at 06:39 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-02-08, 06:44 AM
davestar057 davestar057 is offline
Wannabe Coder
 
Join Date: Dec 2007
Posts: 113
Thanks: 1
Thanked 1 Time in 1 Post
PHP Code:

if (isset($_POST['submitted'])) {


    
// Check for an uploaded file.
    
if (isset($_FILES['upload'])) {
        
        
// Validate the type. Should be jpeg, jpg, or gif.
        
$allowed = array ('image/gif''image/jpeg''image/jpg''image/pjpeg');
        if (
in_array($_FILES['upload']['type'], $allowed)) {
        
            
// Move the file over.
            
if (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/{$_FILES['upload']['name']}")) {
            
                echo 
'<p>The file has been uploaded!</p>';
            
            } else { 
// Couldn't move the file over.
            
                
echo '<p><font color="red">The file could not be uploaded because: </b>';
        
                
// Print a message based upon the error.
                
switch ($_FILES['upload']['error']) {
                    case 
1:
                        print 
'The file exceeds the upload_max_filesize setting in php.ini.';
                        break;
                    case 
2:
                        print 
'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
                        break;
                    case 
3:
                        print 
'The file was only partially uploaded.';
                        break;
                    case 
4:
                        print 
'No file was uploaded.';
                        break;
                    case 
6:
                        print 
'No temporary folder was available.';
                        break;
                    default:
                        print 
'A system error occurred.';
                        break;
                } 
// End of switch.
                
                
print '</b></font></p>';

            } 
// End of move... IF.
            
        
} else { // Invalid type.
            
echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>';
            
unlink ($_FILES['upload']['tmp_name']); // Delete the file.
        
}

    } else { 
// No file uploaded.
        
echo '<p><font color="red">Please upload a JPEG or GIF image smaller than 512KB.</font></p>';
    }
            
// End of the submitted conditional.
?>
    
<form enctype="multipart/form-data" action="upload_image.php" method="post">

    <input type="hidden" name="MAX_FILE_SIZE" value="524288">
    
    <fieldset><legend>Select a JPEG or GIF image to be uploaded:</legend>
    
    <p><b>File:</b> <input type="file" name="upload" /></p>
    
    </fieldset>
    <div align="center"><input type="submit" name="submit" value="Submit" /></div>
    <input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html> 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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
Simple image upload lewiscornwell Job Offers & Assistance 2 11-21-07 07:14 PM
Image Upload Perms automatically set to 600 progress Perl 2 10-05-05 01:19 PM
ASP upload prob minority ASP 1 06-27-05 09:35 AM
image resize and upload ascanio PHP 0 06-25-05 07:37 PM
Image upload and if / else mdhall PHP 4 11-14-04 04:12 PM


All times are GMT -5. The time now is 12:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.