Clixint Tech. Blog
Where we post most up-to-date information about our products and other technologies.
Easy way to Upload files using PHP

Ali Imran 0
Working as Chief Operating Officer
Posted in PHP & MySQL

There is a traditional way of uploading files in php usually developers use, that is, use functions is_uploaded_file() and move_uplaoded_file(). These functions my create problems sometimes. function move_uplaoded_file() sometimes does not let you move file to a specific folder, may be becuase your account does not have permission to move a temporary file to some folder in your account. I encountered same problem when my client reported me that he has ful permissions to write a file anywhere in any folder, and he has successfully chmod-ed the folders to 777 / 666 (on unix server), but he still cannot get the admin panel script to perform uploading of image. Then I came to know that I must not use move_uplaoded_file, but find some other way to read the file data and write it myself whereever I want. So I came up with following things.

//First check types and errors and make sure file is right

$file_to_read = $_FILES['myfilevar']['tmp_name']; //access tmp_name that is temporary file

$file_data = implode("",file($file_to_read));

Now we have full data of file in variable $file_data and we can use it to write the file anywhere allowed.

For example you wish to write the uplaoded file 'mynewfile.png' to a sub folder called 'myfiles', you write as.

$f = fopen("./myfiles/mynewfile.png","w");

That's it - you no more need to use move_uploaded_file.

Share this post : Facebook

0 Response(s) to Easy way to Upload files using PHP

Be the first one to post a comment.

Post a Comment ! All comments are moderated
Please fill the form below to enter your comment.

Enter Your Name
Enter Your Email
Enter Your Website

Clixint Technologies

Clixint Technologies provides the most cost effective and user friendly IT solutions with a clear view and direct approach, keeping our customer's audience in mind. Contact Us

Blog Categories

Building Businesses Since 2002

Clixint Technologies. is a registered international firm focused on conceiving, developing and distributing customer-focused IT solutions for the large as well as small to mid-sized businesses that are serious about excelling and achieving success. We provide conceptual, functional and presentational development for the global business community through out-of-the-box web strategy, design and technology solutions. We have been delivering quality products since 2002.
Privacy Policy
Terms & Conditions