Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Image Upload help!

Featured Replies

So, I have the following code:

<?
function getImgFileType($type) {
if($type=='image/jpeg' or $type=='image/pjpeg' or $type=='image/jpg') $type='jpeg';
elseif($type=='image/gif') $type='gif';
elseif($type=='image/png') $type='png';
else $type='';
 return $type;
}
?>
<?
if(isset($_POST['submit'])) {
 $img='poza';
 $name=$_FILES[$img]['tmp_name'];
 $type=$_FILES[$img]['type'];
 $type=getImgFileType($type);
 $func="imagecreatefrom$type";

 $image=$func($name);

}
?>
<br />
<br />
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
	<input name="poza" type="file" />
<input type="submit" name="submit" value="Send File" />
</form>

 

When I try files larger than 1mb, it gives me the following error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13824 bytes) in /home/mobilado/public_html/admin/t.php on line 21

 

Why??? :angry:

  • Author

P.S.

 

I tried all kind of things like:

ini_set('post_max_size',"40M");

ini_set('upload_max_filesize',"40M");

ini_set("memory_limit","40M");

 

Trying to limit the memory to 40M, didn't work!

  • Author

I managed to do it, but only if i set the memory_limit higher than 40M, isn't there another solution?

  • Author

I noticed that, even though I set my memory_limit up to 40M, i can't upload files larger than 2mb.

Help somebody?

Hi Adi

 

Are you on shared hosting?

 

Also, the edit feature is there for a reason :p

  • Author

Yes, I'm on shared hosting.

 

Sorry for not editing my messages, but I wrote them kinda in a rush.

Sorry again.

the server is probably set up not to allow in-script setting changes, and as such the default limit of 2M applies. You will need to search and replace the php.ini for "2M" with "40M" to make it work, and this change will be global.

  • Author

I don't have access to php.ini

How can I find out if I am allowed to do in-script changed?

 

If i set up the memory_limit with ini_set, if later in the script i echo somewhere with ini_get the memory limit, it gives me the value i set

  • Author

Hohohoh!!!

I did it! :yahoo:

Just throw this:

php_value upload_max_filesize 50M

in your .htaccess and it will work!

Finally!!!!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.