Hi i have this script to upload and replace the exciting image which is good. The one thing i can not figure out is i would like to resize any images that are uploaded, to like 60x60.
any ideas ?

<?php


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

        $newext = '.png';
        $filename = $_FILES["file"]["name"];
        $file_basename = substr($filename, 0, strripos($filename, '.')); // get file extention
        $file_ext = substr($filename, strripos($filename, '.')); // get file name
        $filesize = $_FILES["file"]["size"];
        $width = 20;
        $height = 20;
        $allowed_file_types = array('.jpg','.png','.gif');

        if (in_array($file_ext,$allowed_file_types)  &&  ($filesize < 2000)) {

            // rename file
            $newfilename = $_SESSION['ls_user'] . $newext;

            {       
                move_uploaded_file($_FILES["file"]["tmp_name"], "avatar/" . $newfilename);
                echo "File uploaded successfully.";         
            }

        } elseif (empty($file_basename)) {  
            // file selection error
            echo "Please select a file to upload.";     
        } elseif ($filesize > 2000) {   
            // file size error
            echo "The file you are trying to upload is too large.";     
        } else {
                    // file type error
            echo "Only these file typs are allowed for upload: " . implode(', ',$allowed_file_types);
            unlink($_FILES["file"]["tmp_name"]);        
        }

    }

    ?>

<p><form action="" method="post" enctype="multipart/form-data"></p>
    <input type="file" name="file" id="file">
    <input type="submit" name="submit" id="Submit" value="Submit"></form>

thank you

Member Avatar for LastMitch

@TKO

Hi i have this script to upload and replace the exciting image which is good. The one thing i can not figure out is i would like to resize any images that are uploaded, to like 60x60.any ideas ?

There's a lot of resized images with uploading scripts out there I'm not sure why you would choose this one and that you need someone to modify it?

Here is a link to an example that is closest to your:

http://www.9lessons.info/2009/03/upload-and-resize-image-with-php.html

Thanks for the idea
My sript uploads all images these other ones dont upload gif png ext.
Any ideas to modify this one

Member Avatar for LastMitch

@TKO

My sript uploads all images these other ones dont upload gif png ext.

Did you test out teh script and also put extension that don't upload

This your code of extension:

 $allowed_file_types = array('.jpg','.png','.gif');

This the code from the link:

if ($image) {
$filename = stripslashes($_FILES['file']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
echo ' Unknown Image extension ';
$errors=1;
}
else{
$size=filesize($_FILES['file']['tmp_name']);

if ($size > MAX_SIZE*1024){
echo "You have exceeded the size limit";
$errors=1;
}

if($extension=="jpg" || $extension=="jpeg" ){
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png"){
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else if($extension=="gif"){
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else {
$src = imagecreatefromgif($uploadedfile);
}

Any ideas to modify this one

No, I won't modify the current code you post.

It's up to you whether you pick this one because it's very simple.

I mean what so hard just changing extensions?

I already add gif?

All You just need to add a few more lines and you're done!

thanks for your input LastMitch the problem is most sciprts upload gifs but lose the animation.

Member Avatar for LastMitch

thanks for your input LastMitch the problem is most sciprts upload gifs but lose the animation.

Uploading images don't lose quality. Resizing yes, like most resized scripts. There's really not much to prevent that unless you buy a software or a shareware scripts from a company.

thank you, i just set size when i called on the pics. seems to work for me.

$image1 = "<img src=avatar/$image0.png width=30 height=30 />";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.