Pages

Showing posts with label upload. Show all posts
Showing posts with label upload. Show all posts

Friday, May 10, 2013

Upload Files to Amazon S3(Simple Storage) using PHP

Recently I was working on a project which required to upload files on Amazon Simple storage service which is S3

The 2 tutorials which worked perfectly for me are mentioned in links as follows

http://www.9lessons.info/2012/08/upload-files-to-amazon-s3-php.html

http://net.tutsplus.com/tutorials/php/how-to-use-amazon-s3-php-to-dynamically-store-and-manage-files-with-ease/


The latest SDK has somefor PHP 2 has some limitations I will point further...

Tuesday, November 6, 2012

Unable to upload files from form

enctype=multipart/form-data

Always when adding input type="file" in your form add this parameter to your form tag as a property.....



now what does this mean

When submitting a form, you're trying to say your browser to send via the HTTP protocol a message on the network properly enveloped in a TCP/IP protocol message structure. When sending data, you can use POST or GET modes to send data using HTTP protocol. POST tells your browser to build an HTTP message and put all content in the header of the message ( a very useful way of doing things, more safe and also flexible). GET has some constraints about data representation and length.
When sending a file, it is necessary to tell HTTP protocol that you are sending a file having several characteristics and information inside it. In this way it is possible to consistently send data to receiver and let him open the file with the current format and so on... This is a requirement from the HTTP protocol as shown here:http://www.w3.org/TR/html401/interact/forms.html
You cannot send files using default send enctype parameters because your receiver might encounter problems reading it (consider that a file is a descriptor for some data for a specific operating system, if you see things this way, maybe you'll understand why it is so important to specify a different enctype for files).
This way of doing things also ensures that some security algorithms work on your messages. This information is also used by application-level routers in order to act as good firewalls for external data.

wordpress media upload cheating ' uh issue

Its and issue with media_upload.php and comes with some plugins on updating Wordpress

The solution is simple

if using SMOF
 
add_action('init','optionframework_mlu_init');
'posttype'=>'options'

If not using SMOF

tb_show('','media_upload.php?post_id='+jquery('#post_ID').attr('name')+'....)

find this line and change  

'post_id=0'

that's it

I know it's changing the core but if plugin does not releases its update that's how we need to manage.

Sunday, July 8, 2012

A file upload helpful php code

if(isset($_POST['sendmail']))
{
    //echo "
";
    //print_r($_POST);
    //print_r($_FILES);
    //echo "
";

    //$attachment = chunk_split(base64_encode(file_get_contents($_POST['upload'])));

    //Get the uploaded file information
    $name_of_uploaded_file =
    basename($_FILES['upload']['name']);
    //echo $name_of_uploaded_file;
    //get the file extension of the file
    $type_of_uploaded_file =substr($name_of_uploaded_file,strrpos($name_of_uploaded_file, '.') + 1);
    //echo $type_of_uploaded_file;
    $size_of_uploaded_file =$_FILES["upload"]["size"]/1024;
    //echo $size_of_uploaded_file;
    $max_allowed_file_size = 100; // size in KB
    $allowed_extensions = array("doc", "pdf", "docx","txt"winking smiley;
    //Validations
    if($size_of_uploaded_file > $max_allowed_file_size )
    {
        $errors .= "\n Size of file should be less than $max_allowed_file_size";
    }
    //------ Validate the file extension -----
    $allowed_ext = false;
    for($i=0; $i    {
        if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
        {
            $allowed_ext = true;
        }
    }
    if(!$allowed_ext)
    {
        $errors .=
        " Only the following file types are supported: ".implode(',',$allowed_extensions);
    }

    if(!isset($errors))
    {
        move_uploaded_file($_FILES["upload"]["tmp_name"],WP_CONTENT_DIR.'/uploads/'.basename($_FILES['upload']['name']));
        $to=  get_option('ugmm_career_email');
        $subject=get_option('ugmm_career_upload_field');
        $message="File uploaded by".get_option('ugmm_career_upload_field');
        $headers = 'From:upload<'.$to.'>';
        $attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["upload"]["name"]);
        wp_mail($to,$subject,$message,$headers,$attachments);
        $sentmail=true;
    }
    else
    $sentmail=false;
}
?>