note 72976 added to ref.curl

From: Date: Tue, 06 Feb 2007 14:25:34 +0000
Subject: note 72976 added to ref.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-122926@lists.php.net to get a copy of this message
I am having a hard time finding a way to display a progress bar for CURL on PHP. I am a little unfamiliar with CURL but there must be an easy implementation to have some kind of progress meter display on the user's browser about the FTP upload. <? if($_POST['submit']) { $server = 'ftp://www.signsrus.info'; $u_name = 'user'; $p_word = 'pass'; $up_file = $HTTP_POST_FILES['file']['tmp_name']; $srvr_path = '/uploads/'; $new_name = $HTTP_POST_FILES['file']['name']; // Append path & uploaded file name to server name, pass with CURLOPT_URL. $url = $server . $srvr_path . $new_name; // fopen() upload file for handle to pass with CURLOPT_INFILE. $fp = fopen($up_file, 'r'); if (!$fp) { echo 'Failed to open upload file.' . '<br />'; exit; } if (!($ch = curl_init())) { echo 'Unable to allocate resource.' . '<br />'; exit; } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, $u_name . ':' . $p_word); // If true w/CURLOPT_RETURNTRANSFER server output returned by curl_exec(). // (Usually no output w/FTP, anyway.) // If false, curl_exec() will return true on success. // Either way curl_exec() returns false on failure. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_UPLOAD, true); curl_setopt($ch, CURLOPT_INFILE, $fp); // Show progress curl_setopt($ch, CURLOPT_PROGRESS, 1); // Pass true w/CURLOPT_TRANSFERTEXT for ascii, false for binary. curl_setopt($ch, CURLOPT_TRANSFERTEXT, true); // File size w/CURLOPT_INFILESIZE must be accurate for clean transfer. curl_setopt($ch, CURLOPT_INFILESIZE, filesize($up_file)); // Everything's ready, now curl_exec() does it all. $curl_return = curl_exec($ch); if ($curl_return === false) { // Show failure info. echo 'curl_exec() failed.' . '<br />'; echo 'curl_errno() = ' . curl_errno($ch) . '<br />'; echo 'curl_error() = ' . curl_error($ch) . '<br />'; } else { // Show success info. echo 'File Transferred Successfully.' . '<br />'; echo '<br /><b>curl_getinfo()</b>' . '<br />'; foreach (curl_getinfo($ch) as $key => $value) { echo $tab . $key . ' => ' . $value . '<br />'; } } curl_close($ch); } ?> <html> <head> </head> <body> <form name="upload" method="post" action="upload.php" enctype="multipart/form-data"> <input type="file" name="file"> <br><br> <input type=submit value="Submit" name="submit" /> </form> </body> </html> ---- Server IP: 64.71.164.2 Probable Submitter: 69.1.16.251 ---- Manual Page -- http://www.php.net/manual/en/ref.curl.php Edit -- https://master.php.net/note/edit/72976 Del: integrated -- https://master.php.net/note/delete/72976/integrated Del: useless -- https://master.php.net/note/delete/72976/useless Del: bad code -- https://master.php.net/note/delete/72976/bad+code Del: spam -- https://master.php.net/note/delete/72976/spam Del: non-english -- https://master.php.net/note/delete/72976/non-english Del: in docs -- https://master.php.net/note/delete/72976/in+docs Del: other reasons-- https://master.php.net/note/delete/72976 Reject -- https://master.php.net/note/reject/72976 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122926) next »