Jump to content

File upload issue


Deoctor

Recommended Posts

Hai

I have created this code for uploading the files.It uploads the jpg, png files correctly. but if i check with gif it is giving the problem. I have checked that it is not creating a temp name for that file types, can any one tell me y is this happening.

<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<?php 
ini_set("display_errors",1);
error_reporting(E_ALL);
$target = "upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$uploaded_type=strtolower(substr($_FILES['uploaded']['name'],strrpos($_FILES['uploaded']['name'],'.')+1));
print_r($_FILES['uploaded']);
echo "111 ".$uploaded_type;

//This is our limit file type condition 
if (($uploaded_type=="gif")||($uploaded_type=="jpg")||($uploaded_type=="png")) 
{ 

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{ 
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; 
} 
else 
{ 
echo "Sorry, there was a problem uploading your file."; 
} 

} 
else 
{ 
echo "These files cannot be uploaded<br>"; 
} 
?>

Link to comment
Share on other sites

You must check if the file was uploaded without any errors before you can reference any of the ['name'], ['type'], ['size'], or ['tmp_name'] elements of the $_FILES['uploaded'] array.

 

The whole $_FILES array will be empty if you exceed the post_max_size setting and $_FILES['uploaded']['error'] will only be zero if the file was uploaded successfully.

 

Ref: http://www.php.net/manual/en/ini.core.php#ini.post-max-size

http://www.php.net/manual/en/features.file-upload.errors.php

 

Link to comment
Share on other sites

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.