Jump to content

brownka

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by brownka

  1. ok ive never seen this before...apparently my include file had some white space? in it and was corrupting the file.but anyways i took it out and it works now.....ive been going crazy with this for two days fdownload.php------------------------------------------------------- <?php if ($_GET['submitnum']) { include ("dbconnect.php"); $submitnum = $_GET['submitnum']; $query = "select filepath, filetype, filename, filesize from submitted where submitnum=$submitnum"; $result = @mysql_query($query, $conn); list($filepath, $filetype, $filename, $filesize) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$filename"); header("Content-length: $filesize"); header("Content-type: $filetype"); readfile($filepath); } ?>
  2. anyone have any suggestions? ive been stuck on this for a couple days now. any ideas would be great.thanks!
  3. I am storing the path to an uploaded file in a mysql database and i want to download that file and save it. I keep getting corrupt, garbled, and misnamed files when i download them. I have checked the uploaded file on my server and so i know that it is intact. Any help would be great or if anyone has a script that already works i would love to look at it! This is driving me crazy!! below is all my code. THANKS for your help!! fileupload.php----------------------------------------------------------- if($_POST['file'] != "none" && $_FILES['file']['size'] > 0) { $class=$_POST['sclass']; $description=$_POST['description']; $duedate=$_POST['duedate']; $file=$_POST['file']; $_SESSION['username']="brownka"; $id=$_SESSION['username']; $uploaddir = "C:/Apache2/htdocs/desk/submitted/"; $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; $filepath = $uploaddir . $filename; $result = move_uploaded_file($tmpname, $filepath); if (!$result) { echo "Error uploading file"; exit; } $insert = "insert into submitted (userid, classnum, description, filepath, filename, filesize, filetype) values ('$id', '$class', '$description', '$filepath', '$filename', '$filesize', '$filetype')"; $result = mysql_query($insert, $conn) or die('Query error:' . mysql_error()); if ($result==0) { echo "An error has occurred. Assignment was not submitted."; } else { echo "You have successfully submitted the assignment."; } } else { echo "You must select a file for upload!"; } ------------------------------------------------------------------- fdownload.php------------------------------------------------------- <?php if ($_GET['submitnum']) { include ("dbconnect.php"); $submitnum = $_GET['submitnum']; $query = "select filepath, filetype, filename, filesize from submitted where submitnum=$submitnum"; $result = @mysql_query($query, $conn); list($filepath, $filetype, $filename, $filesize) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$filename"); header("Content-length: $filesize"); header("Content-type: $filetype"); readfile($filepath); } ?> ----------------------------------------------------------- create table submitted( submitnum int not null auto_increment, userid varchar(10) not null, classnum int not null, filepath varchar (200) not null, description tinytext not null, filename varchar(50) not null, filesize varchar(50) not null, filetype varchar(50) not null, time timestamp default current_timestamp, flag int default 0 not null, primary key (submitnum), index (userid), index (classnum), foreign key (userid) references student(userid), foreign key (classnum) references classes(classnum)) ENGINE=InnoDB;
  4. ah thanks for the help but im trying to finish this up before i leave town tomorrow for a job interview!
  5. haha yeah im still learning ToonMariner. Paybe you could help me out with a problem? i have a thread posted..... http://www.phpfreaks.com/forums/index.php/topic,139062.0.html
  6. spotted an error in my reply....fixed below in the red...sorry At the top of every page (before any php or html code) that you only want the admin user to access put include("adminheader.php"); then the files needed are below. should work fine....ive used it in projects.goodluck! adminheader.php------------------------------------------------------------------------ <?php session_start(); // start session if(!isset($_SESSION['username'] or $_SESSION['username']!='admin')) //check to see if the username is set in the session and if it ='admin' { include("logout.php"); //if its not set or wron user call logout.php exit(); //exit } ?> ---------------------------------------------------------------------------------------- logout.php----------------------------------------------------------------------------- <?php session_start(); session_unset(); //unset any session variable set session_destroy(); //end the session header("location:index.php"); //send them back to the login page or a home page ?> ----------------------------------------------------------------------------------------
  7. At the top of every page (before any php or html code) that you only want the admin user to access put include("adminheader.php"); then the files needed are below. should work fine....ive used it in projects.goodluck! adminheader.php------------------------------------------------------------------------ <?php session_start(); // start session if(!isset($_SESSION['username'] or $_SESSION['username']=='admin')) //check to see if the username is set in the session and if it ='admin' { include("logout.php"); //if its not set or wron user call logout.php exit(); //exit } ?> ---------------------------------------------------------------------------------------- logout.php----------------------------------------------------------------------------- <?php session_start(); session_unset(); //unset any session variable set session_destroy(); //end the session header("location:index.php"); //send them back to the login page or a home page ?> ----------------------------------------------------------------------------------------
  8. anyone have some insight? have looked everywhere for some info but i cant seem to find out what is wrong here. any help would be greatly apppreciated!! Thanks!
  9. put all the names of the tabes in an array and use truncate. im a noobie but im sure there is a way to query all the names of the tables to automate the array creation. goodluck! $tables=array("grades","inclass","submitted","posted","classes"); foreach($tables as $table) { $query = "truncate $table"; $result = mysql_query($query,$conn) or die("Query error");
  10. I have a database set up that stores a $filepath and other file info and a download script to retrieve the file and download it. Whenever I try to download a file it changes the name of the file im trying to download to the name of the the full path on the server (ex file is on server as "b3e9e4e56d146bdb45ef727f30986f95.doc" but saves as "C--Apache2-htdocs-website-submitted-b3e9e4e56d146bdb45ef727f30986f95" when i download it.) And the files are corrupt and filled with jibberish if they can be opened. Any help would be appreciated this is driving me insane and im on a deadline to finish this up tongiht!! Thanks!!! fdownload.php ------------------------------------------------------------------------------------------------------ <?php if ($_GET['submitnum']) { include ("dbconnect.php"); $submitnum = $_GET['submitnum']; $query = "select filepath, filetype, filename, filesize from submitted where submitnum=$submitnum"; $result = @mysql_query($query, $conn); list($filename, $filetype, $filesize, $filepath) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$filename"); header("Content-length: $filesize"); header("Content-type: $filetype"); readfile($filepath); exit; } ?> ------------------------------------------------------------------------------------------ fupload.php ------------------------------------------------------------------------------------------ if($_POST['file'] != "none" && $_FILES['file']['size'] > 0) { $uploaddir = "C:/Apache2/htdocs/finalproject/posted/"; $classnum=$_POST['class']; $description=$_POST['description']; $duedate=$_POST['duedate']; $file=$_POST['file']; $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; $ext = substr(strrchr($filename, "."), 1); $randname = md5(rand() * time()); $filepath = $uploaddir . $randname . '.' . $ext; $result = move_uploaded_file($tmpname, $filepath); $query = "insert into posted (userid, duedate, classnum, description, filename, filesize, filetype, filepath ) values ('$id', '$duedate', '$classnum','$description', '$filename', '$filesize', '$filetype', '$filepath')"; $result=mysql_query($query) or die("query error"); if ($result==0) { echo "An error has occurred. Assignment was not posted."; } else { echo "You have successfully posted an assignment."; } } else { echo "You must select a file for upload!"; } } --------------------------------------------------------------------------------
  11. Thanks for the suggestion but i found an error in my code....i highlighted it below. i was selecting the a blob from a previous try (saving the file in a blob in mysql) but i should have been selecting the filepath since im storing the file in a fodler on the server now. But it still does not work. It now downloads and saves my files with the full path in the name (ex file is on server as "b3e9e4e56d146bdb45ef727f30986f95.doc" but saves as "C--Apache2-htdocs-website-submitted-b3e9e4e56d146bdb45ef727f30986f95" when i download it.). And to top it off the file is corrupt and cant be read. Any more suggestions? I know this shouldnt be this hard. Thanks!! ------------------------------------------------------------------------------------------------------------------------------------------ fdownload.php ------------------------------------------------------------------------------------------------------ <?php if ($_GET['submitnum']) { include ("dbconnect.php"); $submitnum = $_GET['submitnum']; $query = "select filedata, filetype, filename, filesize from submitted where submitnum=$submitnum"; $result = @mysql_query($query, $conn); list($filename, $filetype, $filesize, $filepath) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$filename"); header("Content-length: $filesize"); header("Content-type: $filetype"); readfile($filepath); exit; } ?>
  12. This has been driving me nuts. I have a database set up that stores a $filepath and other file info and a download script to retrieve the file and download it. Whenever I try to download a file it changes the name of the file im trying to download to the name of the php page (example: filename:"ads876dfa8798adfdf.txt" but it downloads as "fdownload.php". I beleive that i have all the content header set properly but i need some fresh eyes. Any help would be appreciated! fdownload.php ------------------------------------------------------------------------------------------------------ <?php if ($_GET['submitnum']) { include ("dbconnect.php"); $submitnum = $_GET['submitnum']; $query = "select filedata, filetype, filename, filesize from submitted where submitnum=$submitnum"; $result = @mysql_query($query, $conn); list($filename, $filetype, $filesize, $filepath) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$filename"); header("Content-length: $filesize"); header("Content-type: $filetype"); readfile($filepath); exit; } ?> ------------------------------------------------------------------------------------------ fupload.php ------------------------------------------------------------------------------------------ if($_POST['file'] != "none" && $_FILES['file']['size'] > 0) { $uploaddir = "C:/Apache2/htdocs/finalproject/posted/"; $classnum=$_POST['class']; $description=$_POST['description']; $duedate=$_POST['duedate']; $file=$_POST['file']; $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; $ext = substr(strrchr($filename, "."), 1); $randname = md5(rand() * time()); $filepath = $uploaddir . $randname . '.' . $ext; $result = move_uploaded_file($tmpname, $filepath); $query = "insert into posted (userid, duedate, classnum, description, filename, filesize, filetype, filepath ) values ('$id', '$duedate', '$classnum','$description', '$filename', '$filesize', '$filetype', '$filepath')"; $result=mysql_query($query) or die("query error"); if ($result==0) { echo "An error has occurred. Assignment was not posted."; } else { echo "You have successfully posted an assignment."; } } else { echo "You must select a file for upload!"; } } --------------------------------------------------------------------------------
×
×
  • 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.