Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Can't upload image at all

images php coding issues or problems here.

Moderators: macek, egami, gesf

Can't upload image at all

Postby Gigga » Tue Oct 09, 2012 6:44 pm

I have this in HTML along with the registration info.

<form action="updatemem.php" method="POST" enctype=multipart/form-data">
<label for="image">Upload profile photo:</label>
<input type="file" name="image" />

In Updatemem.php:
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
{echo "no file";
die;}

And when I choose a file, it goes into "no file". I echoed $file and it is blank. I've been looking all over the web and cant find any info. Please help!
Thanks!
Gigga
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Oct 09, 2012 6:43 pm

Re: Can't upload image at all

Postby seandisanti » Wed Oct 10, 2012 9:34 am

you're missing a double quote on your enctype
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Can't upload image at all

Postby Gigga » Wed Oct 10, 2012 2:25 pm

I compared it so much and I didn't see that. Thank you.
Gigga
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Oct 09, 2012 6:43 pm

Re: Can't upload image at all

Postby seandisanti » Wed Oct 10, 2012 3:03 pm

no problem, did that fix it?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Can't upload image at all

Postby mmshlrfsh » Sat Aug 24, 2013 12:39 am

In form HTML:
Code: Select all
<form action="updatemem.php" enctype="multipart/form-data" method="POST">
<input name="MAX_FILE_SIZE" type="hidden" value="2097152" />
<label for="image">Upload profile photo (MAX 2MB):</label>
<input id="image" name="image" type="file" />
<input type="submit" value="Upload" />
</form>

In Updatemem.php:
Code: Select all
<?php
if(isset($_FILES['image'], $_FILES['image']['name'])) {
    if($_FILES['image']['error'] == 0 && $_FILES['image']['size'] <= 2097152) {
        move_uploaded_file($_FILES['image']['tmp_name'], '/uploads/' . $_FILES['image']['name']);
    }
    else {
        die('Larger than maximum allowed size (2MB).');
    }
}
else {
    die('No file uploaded.');
}
User avatar
mmshlrfsh
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Aug 23, 2013 10:41 pm
Location: Iran - Isfahan

Re: Can't upload image at all

Postby mmshlrfsh » Sat Aug 24, 2013 12:45 am

In form HTML:
Code: Select all
<form action="updatemem.php" enctype="multipart/form-data" method="POST">
<input name="MAX_FILE_SIZE" type="hidden" value="2097152" />
<label for="image">Upload profile photo (MAX 2MB):</label>
<input id="image" name="image" type="file" />
<input type="submit" value="Upload" />
</form>

In Updatemem.php:
Code: Select all
<?php
if(isset($_FILES['image'], $_FILES['image']['name'])) {
    if($_FILES['image']['error'] == 0 && $_FILES['image']['size'] <= 2097152) {
        move_uploaded_file($_FILES['image']['tmp_name'], '/uploads/' . $_FILES['image']['name']);
    }
    else {
        die('Larger than maximum allowed size (2MB).');
    }
}
else {
    die('No file uploaded.');
}
User avatar
mmshlrfsh
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Aug 23, 2013 10:41 pm
Location: Iran - Isfahan

Re: Can't upload image at all

Postby mmshlrfsh » Mon Aug 26, 2013 12:16 am

HTML Form :
Code: Select all
<form action="updatemem.php" enctype="multipart/form-data" method="post">
<input name="MAX_FILE_SIZE" type="hidden" value="2097152" />
<label for="image">Upload profile photo:</label>
<input name="image" type="file" />
<input type="submit" value="Upload" />
</form>

updatemem.php :
Code: Select all
<?php
    if(isset($_FILES['image']) && $_FILES['image']['name'] !== '') {
        $image = &$_FILES['image'];
        $allowedTypes = array('image/gif', 'image/jpeg', 'image/png', 'image/wbmp');
        if($image['error'] == 0 && $image['size'] <= 2097152 && in_array($image['type'], $allowedTypes)) {
            move_uploaded_file($image['tmp_name'], 'uploads/' . $image['name']);
        }
        else {
            echo '<p>There was an error while uploading your image (size or type).</p>' . PHP_EOL;
        }
    }
?>
User avatar
mmshlrfsh
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Aug 23, 2013 10:41 pm
Location: Iran - Isfahan

Re: Can't upload image at all

Postby gauravkachhadiya » Thu Jun 19, 2014 3:10 am

please replace $file = $_FILES['image']['tmp_name']; to $file = $_FILES['image']['name']; and check it..
gauravkachhadiya
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 23, 2014 2:37 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.