Jump to content

File upload script not work


inspire

Recommended Posts

 

When the file upload button(Submit) clicked , file not saved and new-slideinsert.php display and its not directed to new-course.php.

 

i use uploadtemp folder at php to store the temp file

 

Anyone can help me.... ???

<?

session_start();

/*

$name=$_SESSION['u_name'];

if ($_SESSION['u_name']=='')

{

  echo "<script languange = 'Javascript'>

alert('Please Login to access the page');

location.href = 'index.php';

</SCRIPT>";

}*/ ?>

 

<?php

 

echo $idt = $HTTP_POST_VARS['ref'];

 

  mysql_connect("localhost","trainee","123") or die ("Unable to connect server");

  mysql_select_db("gddatab") or die("Unable connect database");

 

 

 

 

  if(isset($_POST['Submit'])&& $_FILES['new_file']['size'] > 0)

  {

      $fileName = $_FILES['new_file']['name'];

      $tmpName  = $_FILES['new_file']['tmp_name'];

      $fileSize =$_FILES['new_file']['tmp_siz'];

      $fileType =$_FILES['new_file']['type'];

     

      $fileopen=fopen($tmpName,'r');

      $content=fread($fileopen,fileSize($tmpName));

      $content=addslashes($content);

      fclose($fileopen);

     

      if(!get_magic_quotes_gpc())

      {

 

      $fileName=addslashes($fileName);

 

      }

 

 

      $sql="insert into ots_slide values ('','$fileName','$fileType','$fileSize','$content','$idt','jeeva','".date('y-m-d')."') ";

      $result=mysql_query($sql) or die ("Action Insert Fail");

     

 

 

        echo "<script languange = 'Javascript'>

alert('File $fileName uploaded');

location.href = 'new-course.php';

</SCRIPT>";

 

}

Link to comment
Share on other sites

You are not saving the file anywhere. You need to use move_uploaded_file() before your fopen() block, like:

 

<?php
move_uploaded_file($_FILES['new_file']['tmp_name'], $destination_file);
?>

 

Where $destination_file contains the destination folder and filename where you want to save your file. for example: "../images/chuck_norris.jpg".

 

EDIT:

Blargh, I just noticed that it might not be what you need since you seem to want to only extract the contents of a posted file instead of saving the actual file. I just got discombobulated... *dies*

Link to comment
Share on other sites

 

When the file upload button(Submit) clicked , file not saved and new-slideinsert.php display and its not directed to new-course.php.

 

i use uploadtemp folder at php to store the temp file

 

Anyone can help me.... ???

<?

session_start();

/*

$name=$_SESSION['u_name'];

if ($_SESSION['u_name']=='')

{

  echo "<script languange = 'Javascript'>

alert('Please Login to access the page');

location.href = 'index.php';

</SCRIPT>";

}*/ ?>

 

<?php

 

echo $idt = $HTTP_POST_VARS['ref'];

 

  mysql_connect("localhost","trainee","123") or die ("Unable to connect server");

  mysql_select_db("gddatab") or die("Unable connect database");

 

 

 

 

  if(isset($_POST['Submit'])&& $_FILES['new_file']['size'] > 0)

  {

      $fileName = $_FILES['new_file']['name'];

      $tmpName  = $_FILES['new_file']['tmp_name'];

      $fileSize =$_FILES['new_file']['tmp_siz'];

      $fileType =$_FILES['new_file']['type'];

     

      $fileopen=fopen($tmpName,'r');

      $content=fread($fileopen,fileSize($tmpName));

      $content=addslashes($content);

      fclose($fileopen);

     

      if(!get_magic_quotes_gpc())

      {

 

       $fileName=addslashes($fileName);

 

      }

 

 

      $sql="insert into ots_slide values ('','$fileName','$fileType','$fileSize','$content','$idt','jeeva','".date('y-m-d')."') ";

      $result=mysql_query($sql) or die ("Action Insert Fail");

     

 

 

        echo "<script languange = 'Javascript'>

alert('File $fileName uploaded');

location.href = 'new-course.php';

</SCRIPT>";

 

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.