Question

I made this php script to add news like this

 $addnewstable .="<table>

             <tr>

             <td>
             <div id=\"boxdiv\">
             <form method=\"GET\" name=\"formone\" enctype=\"multipart/form-data\">
             <textarea name=\"news_textarea\" placeholder=\"Add News Here\"></textarea>
             <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"8388608\"/>
             </td>

             </tr>
             <tr>

             <td>
             <input type=\"text\" name=\"hyperlink\" placeholder=\"Add Hyperlink of news Here\"/>
             </td>

             </tr>

             <tr>

             <td>
             <textarea name=\"statement_textarea\" placeholder=\"Add news statement Here\" ></textarea>
             </td>

             </tr>

             <tr>

             <td>
             <input type=\"file\" name=\"uploadimage\" id=\"fileupload\">   
             </td>

             </tr>
             <tr>

             <td colspan=\"2\" align=\"center\"><input type=\"Submit\" name=\"Submit\" value=\"Add News\"/>

             </form></div>
              </td>

              </tr></table>";

My $_FILES is not working

my php code is

if ($_REQUEST['Submit'] == 'Add News' && isset($_REQUEST['news_textarea']) && isset($_REQUEST['hyperlink']) && isset($_REQUEST['statement_textarea']) ) 
{

$news = mysql_real_escape_string($_REQUEST['news_textarea']);
$hyperlink = mysql_real_escape_string($_REQUEST['hyperlink']);
$statement = mysql_real_escape_string($_REQUEST['statement_textarea']);
$filename = $_FILES['uploadimage']['name'];
$filesize = $_FILES["uploadimage"]["size"];
$filetype = $_FILES["uploadimage"]["type"];
$namelength = strlen($filename);
$imageData = @getimagesize($_FILES["uploadimage"]["tmp_name"]);
$max_filesize =mysql_real_escape_string($_REQUEST['MAX_FILE_SIZE']) ;
$errors = array();
$timeSt = md5(time());   
$time =  date('Y-m-d H:i:s');
$info = pathinfo($filename);
$name = $info['filename'];
$format = $info['extension'];
$imagerealname = basename($name);
$imgpath ="../img/news/".$imagerealname."_".$timeSt."_".$format;
$errorsize = "<span >Error :-</span> Exceeding Image size Upload ";
$errorupload = "<span >Error :-</span> Not an Image Uploading Failed";
echo $filename.$imagerealname;

echo "<br/>".$imgpath.'<br/><br/>';
        if(filesize($_FILES["uploadimage"]["tmp_name"]) > $max_filesize) {

                $errors[] =  $errorsize;
            }

        if($imageData === FALSE || !($imageData[2] == IMAGETYPE_GIF || $imageData[2] == IMAGETYPE_JPEG || $imageData[2] == IMAGETYPE_PNG)) {

                $errors[] = $errorupload;
            }


       // If array ERRORS is empty than insert data in form    

        if (empty($errors)) {

            if (move_uploaded_file($_FILES["uploadimage"]["tmp_name"], $imgpath)) {

            $request=" INSERT INTO  `photoshoot`.`pages_position_id` (`news` ,`hyperlink` ,`statement` ,`imgpath`) VALUES ( '".$news."','".$hyperlink."','".$statement."',  '".$imgpath."')";

echo $request;
            $query = mysql_query($request);
            if($query) {

                echo "<script type=\"text/javascript\">window.location.href = 'http://localhost/ourwork/photoshoot/CMS/samples/sample_new.php';   </script>";
            }
}
}
} 

my $_FILES IS NOT WORKING I CANT figure out why :( need your opinions

Was it helpful?

Solution

By default the method of the <form> tag will be GET. You need to explicitly specify it as POST. Use this:

<form method=\"\" name=\"formone\" enctype=\"multipart/form-data\" method=\"POST\">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top