Jump to content

Recommended Posts

Hi I have a bearbones code for uploading files onto my webspace. It seems to work ok on small files but not bigger ones. The range of working file sizes doesn't consistent.

 

I am a real novice with php but here is my code so far:

 


$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];

if (!empty($_POST['uploadDownload'])){ 
if ($error >0) {
		die("Error uploading file! Code $error.");
	}else{	
		if ($type == "application/x-zip-compressed")	{
			move_uploaded_file($temp, $ddir.$name);
			print_r($type);
			//load simpleForm.php page using javascript
			echo ("<script>
			<!--
			location.replace(\"simpleForm.php\");
			-->
			</script>");			
		}else{
		echo "Wrong file type";	
		}
}

 

and here is the html code:

 

<form enctype="multipart/form-data" action="logosProcessor.php" method="POST">
  <p>
    <input name="newLogoName" type="text" size="25" value="<?php echo $_POST['logoListDropDown']; ?>">
    <input type='submit' name="updateLogoName"  value="Update Logo Name"/>
    <input type='submit' name="deleteLogo" value="Delete Logo"/>
    <input type="hidden" name="oldLogoName" size="25"  value="<?php echo $_POST['logoListDropDown']; ?>">
  </p>
  <p>
    <input type="file" name="myfile">
    <input name="uploadLogo" type='submit' value="upload" >
  </p>
</form>

 

I have tried to create a php.ini file in same directory that the rest of my php files for this webapp but that was just a guess and I don't really know what I'm doing.

 

The php.ini file looks like this in totallity:

 


#!/bin/sh
upload_max_filesize = 50M 
post_max_size = 100M

 

Any help would be very gratefully received!

 

Spencer

Link to comment
https://forums.phpfreaks.com/topic/190931-only-small-files-seem-to-upload-ok/
Share on other sites

Have you tried adding the MAX_FILE_SIZE option in the HTML part of your code? If not, then you could try this:

 

<input type="hidden" name="MAX_FILE_SIZE" value="512000" />

 

The MAX_FILE_SIZE value is the maxium number of bytes you want to be allowed while uploading a file. So 512,000 bytes is 500KB. So if you wanted it to be equal to 50MB you would need to change that value to 52428800. So you whole html code should look like this:

 

<form enctype="multipart/form-data" action="logosProcessor.php" method="POST">
  <p>
    <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
    <input name="newLogoName" type="text" size="25" value="<?php echo $_POST['logoListDropDown']; ?>">
    <input type='submit' name="updateLogoName"  value="Update Logo Name"/>
    <input type='submit' name="deleteLogo" value="Delete Logo"/>
    <input type="hidden" name="oldLogoName" size="25"  value="<?php echo $_POST['logoListDropDown']; ?>">
  </p>
  <p>
    <input type="file" name="myfile">
    <input name="uploadLogo" type='submit' value="upload" >
  </p>
</form>

 

 

Adding the MAX_FILE_SIZE field to the form would only serve to limit the maximum size (it would generate an error value of 2) and has nothing to do with getting an error value of 1.

 

Are you sure a local php.ini can be used to change those two settings on your server?

 

What does a phpinfo() statement show for the upload_max_filesize setting?

 

What exact size is the file that is not uploading?

I haven't been able to update any other php.ini file on the server as I don't know where to look.

 

When  I run phpinfo() it says the Loaded Configuration File is: /home/spence13/public_html/portfolioAppFiles/php.ini

 

But above it says: Configuration File (php.ini) Path is: /usr/lib

 

The upload_max_filesize is 5M. Does this also need to be changed? Do I need to worry about max_execution_time being only 30? Is that a timeout or something?

 

Thanks a lot.

 

Spencer

It seems like I cannot navigate to where the other php.ini is. I guess I will have to ask my hosting company to change the required values. Do you know if the local php.ini would over-ride the settings in the main one (that I cannot directly edit)? If they do maybe I haven't written the code for the local php.ini properly.

 

Literally all thee is in it is:

 


[code=php:0]
; Whether to allow HTTP file uploads.
file_uploads = On
; Maximum amount of memory a script may consume (8MB)
memory_limit = 8M
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

 

 

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.