PHP Forums Archive

upload a local file without using input type ="file" using php

Tags: upload, process form

wendy posted on 2009-05-22 15:38:25 #

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);
?>

Comments / discussions

Olaf posted on 2009-05-22 16:53:02 #

You can't upload without the file field.

The file field is the connection between the users PC and the browser/Internet.

Maybe it's possible using java upload?

wendy posted on 2009-05-22 20:58:34 #

Olaf,
Thank you for your reply. Can I upload a local file to server using FTP without using input type = "file".

Olaf posted on 2009-05-22 21:41:47 #

Quote from: wendy"Olaf,
Thank you for your reply. Can I upload a local file to server using FTP without using input type = "file"."

yes using a ftp client (or java), the file field is needed by the browser (html)

you can use an alternative, but these are not standard

wendy posted on 2009-05-24 16:54:43 #

Olaf,
What you mean an alternative? I have no idea about that. Could you please tell me more details about that. Thank you so much.
Have a great long weekend!

Olaf posted on 2009-05-24 18:59:22 #

Wendy, the limitation is that you need file field if you upload a file via html.
An alternative could be an java application check hotscripts.com or google to find a java upload script

wendy posted on 2009-05-24 19:40:47 #

Olaf,
I really appreciate your reply. I do not want to move to Java. I am new to it. My file is a CSV file on a local drive. I only want to read the file and save the data in mySQL database. Is it possible to open and read local file without uploading using PHP.I know the full path of the file. I know PHP is on the server side, sometimes can not open a local file. Is that right?

Olaf posted on 2009-05-24 19:49:52 #

As you describe it, it's not possible without a file field.

wendy posted on 2009-05-24 19:57:15 #

Olaf,
I see. Thank you so much.