PHP - How To Show List Of Files Uploaded By Current Session User.
show list of files uploaded by current session user to the database. I want to show different users when they log in to the website...they can see a list of old files that they have uploaded. can anyone tell me the code/script to this.....please, ty
Similar Tutorialshi everyone i am currently making my website with an uploadform. The upload function is working, but now i am trying to make the site remember the last 5 uploads. The filenames should appear in an array: $aotf[0] $aotf[1] $aotf[2] $aotf[3] $aotf[4] and since all files that can be/are uploaded are images, i want them to be drawed next to each other, each 128x128. THAT is working, but the fetch for images doesn't. When an image is uploaded, i execute this code: $readhandle=fopen("uploaddb.log","r"); $aotf=fread($handle,filesize("uploaddb.log")); fclose($readhandle); $writehandle=fopen("uploaddb.log","w"); fwrite($writehandle,"$aotf\r\n" . "uploadform/gebruikers/" . $naam); fclose($writehandle); then,there is some html code, and then there is this code: $aotf=explode("/n",$aotf); for($i = count($aotf) - 5; $i <= count($aotf); $i++) { echo ' <img src="'. $aotf[$i] . '" width="128" height="128"> '; } when i open the page, all img src's are empty. The writing works, and the folder of the image is 7777 chmod and the images draw on the screen, but not as the last uploaded. Does anyone know how to make this work? maybe even without a fwrite? Thank you, masterens EDIT: i cannot use mysql At the moment I have been uploading files to my server using <input type='files'> and binary encrytion. I would like to have more controll over the files tmp_name. is there a way to assing it befor hand? Hi All, I'm trying to validate file types and keep seeing an error. I only allow .gif, .jpg or .png. However, if I upload any of those file types, I get an error message.... If I echo out $filetypeCheck, I get image/png, which is corrent... Code: [Select] $filetypeCheck = $_FILES["file"]["type"]; if( ($filetypeCheck != "image/gif") || ($filetypeCheck != "image/jpeg") || ($filetypeCheck != "image/png") ) { $val_error[] = 'File Type Error! (.gif, .jpg and .png only)'; } Whats going on here? Hi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; Hello I am using the code:
<?php Is it better to store uploaded images as 'content' in the database? (like he http://www.techsupportforum.com/forums/f49/tutorial-upload-files-to-database-176804.html).. Or just as a regular file which is referenced in the database..? i am trying to create a small script that will let you
1. Create a PDF from form fields then email that pdf without saving it (was using fpdf for this)
2. within that form there is a file upload - i want to send these along with the pdf crerated in the same email.
this is my code so far, the php sends fine but it is sending in 2 seperate emails and i want it all to send in one
any help would be much apprichated as i am a compleat noob at PHP!
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Email Attachment Without Upload - Excellent Web World</title> <style> body{ font-family:Arial, Helvetica, sans-serif; font-size:13px;} th{ background:#999999; text-align:right; vertical-align:top;} input{ width:181px;} </style> </head> <body> <form action="emailSend.php" method="post" name="mainform" enctype="multipart/form-data"> <table width="500" border="0" cellpadding="5" cellspacing="5"> <tr> <th>Your Name</th> <td><input name="fieldFormName" type="text"></td> </tr> <tr> <tr> <th>Your Email</th> <td><input name="fieldFormEmail" type="text"></td> </tr> <tr> <th>To Email</th> <td><input name="toEmail" type="text"></td> </tr> <tr> <th>Subject</th> <td><input name="fieldSubject" type="text" id="fieldSubject"></td> </tr> <tr> <th>Comments</th> <td><textarea name="fieldDescription" cols="20" rows="4" id="fieldDescription"></textarea></td> </tr> <tr> <th>Attach Your File</th> <td><input name="attachment" type="file"></td> </tr> <tr> <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Send"><input type="reset" name="Reset" value="Reset"></td> </tr> </table> </form> </body> </html> <?php //create PDF and send // download fpdf class (http://fpdf.org) require("fpdf.php"); // fpdf object $pdf = new FPDF(); // generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/) $pdf->AddPage(); $pdf->SetFont("Arial","B",14); $pdf->Cell(40,10, "this is a pdf example"); // email stuff (change data below) $to = "me@domain.com"; $from = "me@domain.com"; $subject = "send email with pdf attachment"; $message = "<p>Please see the attachment.</p>"; // a random hash will be necessary to send mixed content $separator = md5(time()); // carriage return type (we use a PHP end of line constant) $eol = PHP_EOL; // attachment name $filename = "example.pdf"; // encode data (puts attachment in proper format) $pdfdoc = $pdf->Output("", "S"); $attachment = chunk_split(base64_encode($pdfdoc)); // main header (multipart mandatory) $headers = "From: ".$from.$eol; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; $headers .= "Content-Transfer-Encoding: 7bit".$eol; $headers .= "This is a MIME encoded message.".$eol.$eol; // message $headers .= "--".$separator.$eol; $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $headers .= $message.$eol.$eol; // attachment $headers .= "--".$separator.$eol; $headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; $headers .= "Content-Transfer-Encoding: base64".$eol; $headers .= "Content-Disposition: attachment".$eol.$eol; $headers .= $attachment.$eol.$eol; $headers .= "--".$separator."--"; // send message mail($to, $subject, "", $headers); //send uploaded attachments via email $to = $_POST['toEmail']; $fromEmail = $_POST['fieldFormEmail']; $fromName = $_POST['fieldFormName']; $subject = $_POST['fieldSubject']; $message = $_POST['fieldDescription']; /* GET File Variables */ $tmpName = $_FILES['attachment']['tmp_name']; $fileType = $_FILES['attachment']['type']; $fileName = $_FILES['attachment']['name']; /* Start of headers */ $headers = "From: $fromName"; if (file($tmpName)) { /* Reading file ('rb' = read binary) */ $file = fopen($tmpName,'rb'); $data = fread($file,filesize($tmpName)); fclose($file); /* a boundary string */ $randomVal = md5(time()); $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x"; /* Header for File Attachment */ $headers .= "\nMIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed;\n" ; $headers .= " boundary=\"{$mimeBoundary}\""; /* Multipart Boundary above message */ $message = "This is a multi-part message in MIME format.\n\n" . "--{$mimeBoundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; /* Encoding file data */ $data = chunk_split(base64_encode($data)); /* Adding attchment-file to message*/ $message .= "--{$mimeBoundary}\n" . "Content-Type: {$fileType};\n" . " name=\"{$fileName}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mimeBoundary}--\n"; } $flgchk = mail ("$to", "$subject", "$message", "$headers"); if($flgchk){ echo "A email has been sent to: $to"; } else{ echo "Error in Email sending"; } ?> Hi, I have limited experience of using PHP, but having done some searching around it would seem that it is possible to convert audio files that are uploaded through a web page to mp3 using ffmpeg. The audio files would be uploaded using the Uploadify script to subfolders that are named according to the user's login. I would need the PHP script to be able to process all audio files that are either not in MP3 format, or are in MP3 format but greater than 192kbps, deleting the original file after the conversion. Am I right in thinking that this could be achieved using PHP, and if so, can anyone get me started with some code, or a link to a webpage with some code? Also, I am currently using Hostpapa for hosting my website, and I understand that they don't include ffmpeg, and also don't allow ssh. I read on one website that I could still install a compiled version of ffmpeg on a shared server, but I am not sure if this means that it would work on Hostpapa, or whether I would need to change my host to get ffmpeg working. Any advice on any of this would be welcome! Thanks, Nick Hi, I have a question. Can I actually use windows hosting on .php files, or .php files are only suitable to linux domain? Currently I am practicing some php files in the windows domain and I have received a message stated 'no database selected'. However I have definitely created the database, are there any other reasons which may cause this problem? Thanks <?php echo '<select name="race" id="race"> <option value="">--Please select one--</option>'; $dbc = mysql_connect(111', '111', '111', '111') or die(mysql_error()); $query = ("SELECT * FROM race ORDER BY race_id ASC"); $sql = mysql_query($query, $dbc) or die(mysql_error()); while($data = mysql_fetch_array($sql)) { echo'<option value="'.$data['race_id'].'">'.$data['race_name'].'</option>'; } echo '</select><br/>'; mysql_close($dbc); ?> Hi all, Im trying to move files that im uploading from my main domain to a sub domain. I think I can achieve this using passthru? Im having issues with this, can any one point me in the right direction please? Thanks, Phil Hi Basically I've built a CMS where by my clients can upload a number of images. On the success page I want to display the images they uploaded by file name. The issue is the number of images can vary. They may upload 2 or 10 or 50 etc. So far I've come up with this: Code: [Select] // number of files $UN = 3; //I've set this to 3 for now, but this is passed from the upload page! // server directories and directory names $dir = '../properties'; $images = glob($dir.'/*.{jpg}', GLOB_BRACE); //formats to look for $num_of_files = $UN; //number of images to display from number of uploaded files foreach($images as $image) { $num_of_files--; $newest_mtime = 0; $image = 'BROKEN'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..')) { $mtime = filemtime("$dir/$file"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $image = "$file"; } } } } if($num_of_files > -1) //this made me laugh when I wrote it echo $trimmed = ltrim($image, "../properties").'<br />'; //display images else break; } Without this piece of code: Code: [Select] $newest_mtime = 0; $image = 'BROKEN'; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != '.') && ($file != '..')) { $mtime = filemtime("$dir/$file"); if ($mtime > $newest_mtime) { $newest_mtime = $mtime; $image = "$file"; } } } } It shows the first 3 files alphabetically. I want to view the last number of images added. With the above code it simply shows the last image added 3 times! So I need to get the time each image was added and then order by the newest added and limit to the number of images uploaded. Any suggestions please? Kindest regards Glynn I am working on this pictures to upload and when I submit it gives the message below for success but I get this error message which is on the line of $place file Warning: move_uploaded_file(members/5/image01.jpg) [function.move-uploaded-file]: failed to open stream: $check_pic = "members/$id/image01.jpg"; $default_pic = "members/0/image01.jpg"; $newname = "image01.jpg"; $place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "members/$id/".$newname); $success_msg = '<font color="#009900">Your image has been updated, it may take a few minutes for the changes to show... please be patient.</font>'; I've got a page that allows users to upload a file (pdf, jpg, gif png). The user must be logged in in order to upload something. I have a query that checks if the user has already uploaded a file with the same name as the name of the file they are trying to upload. If they have not uploaded the file yet, the file uploads and they get a "Success" message. If the file has already been uploaded by the user, they will get the message, "You have already uploaded that file". When the query goes through, the message that shows is, "You have already uploaded that file". I ensured the file was not already in the database, and it still shows this error. I tried changing the if statement to say: if ($duplicate==0) instead of: if ($duplicate!=0) but it always shows the same error. Any ideas of what could be wrong with my code? my sql table looks like: Field Type Null id int(11) No userid int(11) No artist varchar(50) No title varchar(50) No file varchar(2083) No uploaded varchar(3) No Code: <?php session_start(); if (isset($_SESSION['username'])){ $username = $_SESSION['username']; $submit = $_POST['submit']; include_once('inc/connect.php'); $uploadsql = mysql_query("SELECT * FROM `users` WHERE `username`='$username'"); $uploadrow = mysql_fetch_assoc($uploadsql); $userid = $uploadrow['id']; $folder = "sheets/fromusers/"; if (isset($submit)){ // Name of file $name = $_FILES["location"]["name"]; // Type of file (video/avi) or image/jpg, etc $type = $_FILES["location"]["type"]; //size of file $size = $_FILES["location"]["size"]; //stores file in a temporary location $temp = $_FILES["location"]["tmp_name"]; // if there is an error $error = $_FILES["location"]["error"]; $artist = strtolower($_POST['artist']); $title = strtolower($_POST['title']); // Check if fields are filled in if($artist&&$title){ if ($error > 0) { $sheeterror = "<div id='messageerror'>An error occured. Please try again.</div>"; } else { // Determine the extension of the file // If file is This File.pdf // Then $ext is now equal to pdf $ext = strtolower(substr($name, strrpos($name, '.') + 1)); if ($ext=="pdf" || $ext=="gif" || $ext=="jpeg" || $ext=="jpg" || $ext=="png") { if ($size <= 26214400) // If size <= 25 megabytes { $duplicatecheck = mysql_query("SELECT file FROM upload WHERE id='$userid'"); $duplicate = mysql_num_rows($duplicatecheck); if ($duplicate!=0){ $sheeterror = "<div id='messageerror'>You have already uploaded this file!</div>"; } else{ $sheetquery = mysql_query("INSERT INTO upload VALUES ('','$userid','$artist','$title','$name','no')"); move_uploaded_file($temp, $folder.$name); $success = "<div id='messagesuccess'>Upload Complete!</div><div align='center'>".ucwords($artist)." - ".ucwords($title)."</div>"; } } else{ $sheeterror = "<div id='messageerror'>Your sheet must be less than 25 megabytes.</div>"; } } else { $sheeterror = "<div id='messageerror'>".ucfirst($ext)." files are not allowed!</div>"; } } } else{ $sheeterror = "<div id='messageerror'>Fill In All Fields</div>"; } } } else{ $sheeterror = "<div id='messageerror'>You must be logged in to add sheets!</div>"; } ?> <html> <head> <title>Add Sheet</title> <style> #container{ width: 350px; height: 150px; margin-left: auto; margin-right: auto; background-color: #cccccc; } #formhold{ width: 300px; text-align: right; margin-right: auto; } #messagesuccess{ background-color: #66CD00; width: 350px; margin-left: auto; margin-right: auto; } #messageerror{ background-color: #ff2211; width: 350px; margin-left: auto; margin-right: auto; } </style> </head> <body OnLoad="document.newsheet.artist.focus();"> <?php include_once('inc/nav.php'); ?> <center> <h1>Add Sheet</h1> <br /> <div id="container"> <br /> <div id="formhold"> <form action="addsheet.php" method="post" name="newsheet" enctype="multipart/form-data"> Artist: <input type="text" name="artist" size="30"><br /> Title: <input type="text" name="title" size="30"><br /> Sheet: <input type="file" name="location" size="17"><br /> </div> <center><input type="submit" name="submit" value="Submit"></center> </form> </div> <div id="bottomcont"> <?php echo $success, $sheeterror; ?> </div> </center> </body> </html> Hi, this is what I want to get working: each time I add an entry, it is displayed in a nice html table, and each entry listed in this html table has an UPDATE link that allows the user to update the Price and Description field of the corresponding table in my database. I have also included an upload element which whenever a user chooses an image, it will replace the default fileUploadIcon.jpg with this. Please see the index.php and bellUpdateForm.php below respectively Code: [Select] //index.php <table border="border"> <?php require 'bellConnect.inc.php'; $curImage; $imgIndx=-1;//iniitally $result=mysql_query("SELECT ID, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts"); $indx=0;//***HOW DO I MAKE THIS SHARED SO THAT EACH ENTRY ADDED HAS AN INCREMENTED index appended to end of its name attribute //phpinfo(); //print "Val of \$counter so far: ".$counter; //NB: print table headings if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { //$counter+=1; print "<table border='border'>"; print "<tr> <th>ID</th> <th>Image</th> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> <th colspan=2 align='center'>Modify</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { //extract($row); //if($indx<sizeof($bellProductsArray)) //{ "<tr align='center'> <td>$row[ID]</td> <td>"; if($_POST['upload']) print "<img src=".$_FILES['image']['name'].">"; else print "<img src='fileUploadIcon.jpg' name='image' /> </td> <td> $row[Name] </td> <td> $row[Manufacturer] </td> <td> $$row[Price]</td> <td align='left'>$row[Description]</td> <td>$row[SimSupport]</td> <td><a href='bellUpdateForm.php?ID=$row[ID]'>UPDATE</a></td> <td><a href='bellDeleteForm.php?ID=$row[ID]' name='delete'>DELETE</a></td> </tr>"; //}//END INNER IF $indx++; }//END WHILE }//END BIG IF ?> </table> </body> </html> Code: [Select] //bellUpdateForm.php <?php require 'bellConnect.inc.php'; if($_GET && !$_POST)//this is to make sure that the current entry is selected BUT the updated info NOT submitted yet { if(isset($_GET['ID'])) { $ID=$_GET['ID']; $result=mysql_query("SELECT * FROM bellProducts WHERE ID=$ID"); $row=mysql_fetch_assoc($result); //store the one entry that will be updated print "You are currently updating item: <strong>$row[Manufacturer] $row[Name] </strong> <br /><br />"; "<form action='bellUpdate.php' method='post'> <label> Price:<input type='text' value='$row[Price]' name='price' id='price'></input> </label> <label> Description: <textarea cols='60' rows='3' name='description' id='description'> $row[Description] </textarea> </label> <div> <input type='submit' value='Update entry' name='update' id='update' /> <input type='hidden' value=$row[ID] name='id' /> </div> <input type='reset' value='Reset entry' />"; print "</form>"; }//END INNER IF }//END BIG IF ?> <form method='post' action='index.php' enctype='multipart/form-data' name='uploadImage' id='uploadImage'> <p> <label>Upload image</label> <input type='file' name='image' id='image' /> </p> <p> <input type='submit' value='Upload this' name='upload' id='upload' /> </p> </form> <?php if(array_key_exists('upload', $_POST)) { // define constant for upload folder define('UPLOAD_DIR', 'C:\wamp\www'); // move the file to the upload folder and rename it move_uploaded_file($_FILES['image']['tmp_name'], ! UPLOAD_DIR.$_FILES['image']['name']); } ?> </body> </html> Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros I would appreciate your assistance, there are tons of login scripts and they work just fine. However I need my operators to login and then list their activities for the other operators who are logged in to see and if desired send their clients on the desired activity. I have the login working like a charm and the activities are listed just beautifully. How do I combine the two tables in the MySQL with PHP so the operator Logged in can only make changes to his listing but see the others. FIRST THE ONE script the member logges in here to the one table in MSQL: <?php session_start(); require_once('config.php'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $login = clean($_POST['login']); $password = clean($_POST['password']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); if($result) { if(mysql_num_rows($result) == 1) { session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> ................................................. ................................ Now I need the person who logged in to the table above to be able to make multiple entries to the table below <? $ID=$_POST['ID']; $title=$_POST['title']; $cost=$_POST['cost']; $activity=$_POST['activity']; $ayear=$_POST['aday']; $aday=$_POST['ayear']; $seats=$_POST['special']; $special=$_POST['seats']; mysql_connect("xxxxxx", "xxx350234427", "========") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); mysql_query("INSERT INTO `activity` VALUES ('ID','$title', '$cost','$activity', '$aday', '$ayear', '$special', '$seats')"); Print "Your information has been successfully added to the database!" ?> Click <a href="member-profile.php">HERE</a> to return to the main menu <?php ?> Hi, This may be something for JavaScript but I would like to know if and how it's possible to show who is currently active/viewing the page. Users are logged into the system with their own account. The purpose of this is for a CRM where more than one person may be editing the same record, so undesired overwrites might occur which is what I'd like to avoid with this "other user editing this record" notification. How do I get the current logged in username or id using the Twitter API? Hello everyone.
I have a fully working form that gets data from a user (with $_post array) , and stores it in a database (mysql).
After successfulIy filling the form, I refer him to the "dashboard" page. In this page, i am having trouble to get his details from the database. How should I recognize him as the user that just registered?
should I use a $_post? or maybe a session? could you please give me a clue how to solve this?
|