HTTP file upload using PHP without libcurl?
-
I'm trying to upload a local file to a website of mine, I have a php script waiting to recieve the file, I've been only able to do this using libcurl, particularly this function: function upload($file,$name){ global $portal; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $h=fopen('curl.txt','a'); curl_setopt($ch,CURLOPT_STDERR,$h); curl_setopt($ch,CURLOPT_VERBOSE,true)… curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_URL,"recieve.php"); curl_setopt($ch, CURLOPT_POST, true); // same as <input type="file" name="file_box"> $post = array( "uploadedfile"=> "@$file", "fname" => $name ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $response = curl_exec($ch); } now I'm trying to do it without libcurl any ideas?
-
Answer:
The elegant answer is PEAR: HTTP_Upload. About the same number of lines of code you are showing, but with heavy boilerplate doing more of the lifting. php is capable, with script, using HTTP file protocol. You must be fully aware of each step required or you let the bad guys come in. In brief, using defaults, $_FILES[ 'userfile' ][ 'error' ]: gives any missed milestones using POST UPLOAD_ERR_OK is 0 UPLOAD_ERR_INI_SIZE is 1 UPLOAD_ERR_FORM_SIZE is 2 <?php if (is_uploaded_file($_FILES['fileOfmine'][… { copy($_FILES['fileOmine']['tmp_name'], "/www/htdocs/uploadFolder/".$_FILES['fil… } else { echo "<p>Potential script abuse attempt detected.</p>"; } ?> then you move it boolean move_uploaded_file( filename, filedesitnation ); Yeah, I know it doesn't make much sense. This is a whole chapter in several of my PHP books. But you only need CURL if you are making the file come over like StarTrek transporter. File > atoms > File. Whereas php script you really should restrict types.
YaSSeR at Yahoo! Answers Visit the source
Other answers
yahoo answers will not let me put all of the code in here but you can go to http://bb.dzsoundnirvana.com/viewtopic.php?f=3&t=42 and see the code. This supports checking the MIME (file) type also. Code: <? /*************************** index.php ***************************/ require_once('files.class.php'); $UserInput = array(); foreach($_POST as $key => $value){ $UserInput[$key] = $value; } $files = new files; $files->validate_file($UserInput); ?>
DzSoundNirvana
Related Q & A:
- How To Build Business Directory Using Php Mysql?Best solution by Stack Overflow
- How to upload a file to another server using cURL and PHP?Best solution by Stack Overflow
- how delete node in xml file using php?Best solution by Stack Overflow
- How to read csv file using php?Best solution by Stack Overflow
- How to use angular-file-upload on a page properly?Best solution by angular-file-upload.appspot.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.