WebClient.UploadFile won't upload the file.
-
Hello. Im having a php post site on my server where i can upload files. The problem is just that it doest upload the file at all. Im trying through the php script to upload a file to the database. It works fine when i do it manually from the site, but not when im using UploadFile(). My C# code looks like: string file = "1.jpg"; string url = "http://myserver.net/ind.php?userid="+\_userid+""; try { WebClient InsertClient = new WebClient(); byte[] Response = InsertClient.UploadFile(url, "POST", file); label1.Text = Response.Length.ToString(); } catch (Exception ex) { label1.Text = ex.ToString(); } And the uploadsite looks like and is called "ind.php": $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include "dbcon.php"; $query = "INSERT INTO files (userid, imageData ) ". "VALUES ('".$_GET['userid']."', '$content')"; mysql_query($query) or die('Error, query failed'); echo "
File $fileName uploaded
"; It only adds the userid to the database but without any content of the file. Have anyone got this problem before? -
Hello. Im having a php post site on my server where i can upload files. The problem is just that it doest upload the file at all. Im trying through the php script to upload a file to the database. It works fine when i do it manually from the site, but not when im using UploadFile(). My C# code looks like: string file = "1.jpg"; string url = "http://myserver.net/ind.php?userid="+\_userid+""; try { WebClient InsertClient = new WebClient(); byte[] Response = InsertClient.UploadFile(url, "POST", file); label1.Text = Response.Length.ToString(); } catch (Exception ex) { label1.Text = ex.ToString(); } And the uploadsite looks like and is called "ind.php": $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include "dbcon.php"; $query = "INSERT INTO files (userid, imageData ) ". "VALUES ('".$_GET['userid']."', '$content')"; mysql_query($query) or die('Error, query failed'); echo "
File $fileName uploaded
"; It only adds the userid to the database but without any content of the file. Have anyone got this problem before?And yes, the upload form is a POST method :)
-
Hello. Im having a php post site on my server where i can upload files. The problem is just that it doest upload the file at all. Im trying through the php script to upload a file to the database. It works fine when i do it manually from the site, but not when im using UploadFile(). My C# code looks like: string file = "1.jpg"; string url = "http://myserver.net/ind.php?userid="+\_userid+""; try { WebClient InsertClient = new WebClient(); byte[] Response = InsertClient.UploadFile(url, "POST", file); label1.Text = Response.Length.ToString(); } catch (Exception ex) { label1.Text = ex.ToString(); } And the uploadsite looks like and is called "ind.php": $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include "dbcon.php"; $query = "INSERT INTO files (userid, imageData ) ". "VALUES ('".$_GET['userid']."', '$content')"; mysql_query($query) or die('Error, query failed'); echo "
File $fileName uploaded
"; It only adds the userid to the database but without any content of the file. Have anyone got this problem before?And the output from the upload site is that "File name cannot be empty"..
-
Hello. Im having a php post site on my server where i can upload files. The problem is just that it doest upload the file at all. Im trying through the php script to upload a file to the database. It works fine when i do it manually from the site, but not when im using UploadFile(). My C# code looks like: string file = "1.jpg"; string url = "http://myserver.net/ind.php?userid="+\_userid+""; try { WebClient InsertClient = new WebClient(); byte[] Response = InsertClient.UploadFile(url, "POST", file); label1.Text = Response.Length.ToString(); } catch (Exception ex) { label1.Text = ex.ToString(); } And the uploadsite looks like and is called "ind.php": $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include "dbcon.php"; $query = "INSERT INTO files (userid, imageData ) ". "VALUES ('".$_GET['userid']."', '$content')"; mysql_query($query) or die('Error, query failed'); echo "
File $fileName uploaded
"; It only adds the userid to the database but without any content of the file. Have anyone got this problem before?