hello everyone,
I have a problem on uploading a local file to remote server without using input type ="file". I do know how to upload a local file to server using $_FILES[][] array to get file_name, tmp_name. I want to upload file without using input type ="file". I will put the absolute path of the file in my hardcode. I need to upload the same file daily. I can not use FTP to upload file. I tried to upload file using cURL, but got error message:malformed. The following is my code. Please take a look. What methods I can use to upload local file or open local file to read. I really appreciate your help.
<?php echo "<form action=\"uupload.php?" method=\"post\" enctype=\"multipart/form-data\">"; ?>
<table width="100%" border="0" cellpadding="3" cellspacing="3" class="box">
<tr>
<td width="1000">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
<input name="userfile" type="hidden" class="style1a" id="userfile" value=" "> </td>
</tr>
<tr>
<td width="600"></td></tr>
<tr>
<td width="300" align="center"><input name="upload" type="submit" class="style1a" id="upload" value=" Upload Data" ></td>
</tr>
</table>
</form>
<?php
$post_data = array();
$filename = "03_filename.csv";
$file = "\\\Win.xxx.com\\Upload\\".$filename;
$file = "@".$file;
$post_data = array("userfile" =>"$file");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '/var/www/html/vrw/');
curl_setopt($ch, CURLOPT_UPLOAD, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_CONNECTTIIMEOUT, 600);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
print "
Unable to upload file.";
exit();
}
curl_close($ch);
?>