PHP - Echo Files From Multiple Directories
Hey I have this code which works fine, it echos the file names from a directory into a dropdown box
how can I change it to include more then one directory <?php $dirname = "../images/staff"; $dir = opendir($dirname); echo '<select name="file2">'; echo '<option value="">none</option>'; while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..")) { echo "<option value=".$file.">$file</option>"; } } echo '</select>'; ?> I tried this but it didnt work any help <?php $dirname = "../images/staff"; $dirname .= "../images/boarddirectors"; $dir = opendir($dirname); echo '<select name="file2">'; echo '<option value="">none</option>'; while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..")) { echo "<option value=".$file.">$file</option>"; } } echo '</select>'; ?> Similar TutorialsHey! First timer here, please be gentle on me. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Leettarin Uploader</title> //<link href="style.css" rel="stylesheet" type="text/css" /> <BODY BACKGROUND="Ready.jpg"> <link rel="shortcut icon" href="xxx/twg/favicon.ico"> </head> <?php ob_start(); define("MAX_COUNT", 10); define("UPLOAD_DIRECTORY", "valokuvat/"); define("MAX_SIZE", 1000000); if(!is_dir(UPLOAD_DIRECTORY)) { mkdir(UPLOAD_DIRECTORY, 0777); } if(file_exists($_FILES['file1']['tmp_name'])) { for($i=1; $i<=MAX_COUNT; $i++) { if($_FILES['file'.$i]['size'] > MAX_SIZE) { echo "Liian iso tiedosto!<br>".MAX_SIZE." on raja"; break; } while(file_exists(UPLOAD_DIRECTORY.$_FILES['file'.$i]['name'])) {$_FILES['file'.$i]['name']="$k".$_FILES['file'.$i]['name']; $k++; } move_uploaded_file($_FILES['file'.$i]['tmp_name'], UPLOAD_DIRECTORY.$_FILES['file'.$i]['name']); echo "xxx/waddap/valokuvat/".$_FILES['file'.$i]['name']; exit(); } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" ENCTYPE="multipart/form-data"> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="102400000"> <?php for($i=1;$i<=MAX_COUNT;$i++) { echo " <b><font style=\"color: #00FFFF;\">$i</font></b> <input type=\"file\" name=\"file".$i."\" size=\"75\"><br>"; } ?> <input type="submit" value="Upload"></form><?php ob_end_flush(); exit; ?> Basically, I want this to also display details concerning EVERY uploaded file. I can fix the text and decoration part later, but for now I'd like to know how to make it display information from every uploaded file upon multi-uploading. Information, as in a simple link to the image will do now just fine. So it kind of would redirect you after an upload process to page where are links to all uploads just done. I can only get it to work with 1st file and evidently other files won't even be uploaded then, hm. Also would appreciate a code for blocking other filetypes but .jpeg, .jpg, .png, .gif and .bmp. I'd highly appreciate help! Hello everyone, This is a fairly simple question, but the explanation of the question isn't... I'll do my best. I have a site where my folders/sub-folders/files are arranged similar to this: _ Root Folder -| Root-IncludeFile1.php | Root-IncludeFile2.php | _ | Sub-Folder 1 -| Sub1-File1.php | |_Sub1-File2.php | _ | Sub-Folder 2 -| Sub2-File1.php | |_Sub2-File2.php | _ |_Sub-Folder 3 -| Sub3-IncludeFile1.php |_Sub3-IncludeFile2.php Hopefully that makes sense to everyone. Anyway, I know that to include a file that is in the root folder in file in a sub-folder, I can do this - include("../includefile1.php"); -but I'm trying to include a file that is in a sub folder in a file that is in another sub-folder. For example, I'm trying to include "Sub3-IncludeFile1.php" in "Sub-File1.php" I'm lost on this because I can't get it to work. I'm not getting any error messages except to say that the variables located in the file that should be included are not found. I've tried to do this: include("http://www.mysite.com/Sub-Folder3/Sub3-IncludeFile1.php"); and it doesn't work. Can someone please point me in the right direction? Thanks in advance for your help. I must be brain dead...I've searched everywhere and can't seem to find a snippet for this. I'm just looking for some code to show a directory listing, but only certain files (by extension) and I don't want to show any sub-directories. I thought I might have been able to do this in the .htaccess file, but I can't find anything that will get rid of the sub-directories. So, I figure there must be a way to get a file listing, check the extension, add it to the page, or skip it if it's a sub-directory or doesn't match the extension. Or, I could just be totally, way off...anyway, any help would be greatly appreciated...I'm fairly new to php. Hello I have a problem. I have been trying to copy my music folders structure but not copying the mp3s; instead using the file names as a file name for a .txt file and inserting the URL to the file in the .txt file. Eg. E:\My Music folder 1 folder 1.1 file.mp3 folder 2 folder 3 to G:\My Music folder 1 folder 1.1 file.txt folder 2 folder 3 and inside "file.txt" would be one line saying "http://www.xxx.com/my_music/file.mp3 I have one input upload and need it to go to two directories here is my upload code that handles the move_upload_file portion. Code: [Select] move_uploaded_file($_FILES['fillPDF']['tmp_name'], $strNewsPath . $strFilename); Thanks in advance. This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=356538.0 Hello- I want to create is fairly simple client login. Basically we have an area in our server, a directory really, filled with pw protected directories which house client project sites, basically viewing rooms for graphics and video we post. we have a few sites up and working, but instead of giving our clients a link and a password (which is kinda sloppy) it would be ideal to have them go to a single index page and login from there. I see the client entering a name and password and the script would match it to the directory and they would be taken to their designated client area. Another way would be to select their directory from a drop down and then enter the user and password, though then clients will be able to see other clients names, which would be less than ideal for disclosure reasons. I hope this makes sense. I am not new to html css, but have only a bit of experience with php, so any help would be greatly appreciated. thanks Matt I want to echo out a few subcategories per main category. It should be a maximum of 20 entries per column At this stage I have the following... It echo's the results out in 4 columns and not what I want. Any suggestions? $query = "SELECT adsubcat.name AS subname, adsubcat.linkname AS sublink, adcat.clinkname AS clink FROM adsubcat JOIN adcat ON adcat.id=adsubcat.catid WHERE adsubcat.catid='$catid' ORDER BY adsubcat.name ASC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $count = 0; print '<table style="text-align:left;margin-left:0px;width:943px;">'."\n"; while ($row = mysql_fetch_assoc($result)){ $gal = '<a href="'.$root.'/'.$row['clink'].'/'.$row['sublink'].'">'.$row['subname'].'</a>'; if ($count == 0){ print '<tr>'; } ++$count; print '<td>'.$gal.'</td>'; if ($count == 4){ $count = 0; print'</tr>'."\n"; } } print'</table>'."\n"; } I have the echo statement set up for all files, but what i want to do is put an if statement for example if it contains .pdf or .docx dont echo out an image how would i do this? Code: [Select] <?php $id = explode("/", $_GET['a']); $id = $id[2]; ?> <?php global $allow_client_uploads; ?> <div id="content"> <div class="wrapper content"> <h3 class="page-title"><?php echo $project['name']; ?></h3> <div id="client-controls"> <a href="<?php echo $this->redirect('messages/add/'.$id, true); ?>" class="new-message">Post Message to Admin</a> <?php if($allow_client_uploads): ?> <a href="<?php echo $this->redirect('documents/add/'.$id, true); ?>" class="new-file">Upload A Document</a> <?php endif; ?> <a href="<?php echo $this->redirect('clients/change_password', true); ?>" class="change-password">Change Password</a> </div> <!--<div class="project-progress">Progress <div class="progressbar"> <div id="test" class="progressbar-completed" style="width:<?php // echo $project['progress']; ?>%;"> <div> </div> </div> <div><?php // echo $project['progress']; ?>%</div> </div> </div> --> <ul class="project-phases"> <?php $n=0; global $document_upload_path;?> <?php foreach($project['phases'] as $phase): ?> <li class="clearfix"> <div class="large-bullet"><?php echo ++$n; ?> </div> <h1 class="phase-title"><?php echo $phase ?></h1> <?php if(@count($documents[$n])>0): ?> <ol class="documents"> <?php foreach($documents[$n] as $doc): ?> <li> <a href="<?php echo $this->redirect('documents/download/'.$doc['path'], true); ?>"> <?php echo $doc['description']; ?> <br /> </a> <?php //echo $doc['size']."K - "; ?> <span class="date"><?php // echo date("F j, Y, g:i a", $doc['created']); ?></span> <?php // echo (isset($doc['uploaded_by']))? ", by ".$doc['uploaded_by']:""; ?> <a href="/clientele/uploads/<?php echo $doc['path'];?>" class="lightbox"><?php echo '<img src="/clientele/uploads/'.$doc['path'].'" height="300" width="300">'; ?></a> </li> <?php endforeach;?> </ol> <?php else: ?> <?php endif; ?> </li> <?php endforeach;?> </ul> <div class="sidebar"> <?php if(is_array($messages)): ?> <div class="messagebar">Latest News</div><br /> <?php foreach($messages as $message): ?> <div class="message clearfix"> <p class="body"><?php echo $message['message']; ?></p> <span class="meta"> <?php // echo $message['posted_by']; ?></span> </div> <?php endforeach; ?> <?php endif; ?> </div> <div class="clear"></div> </div> </div> Hi, I want to send the following variable using the $_GET function: Hi All, If someone types in my textarea without any hard returns, it echos the entire text on a single line, which expands my site very very far and screws up the layout. how can I echo the text but limit the number of characters per line before I insert my own line break? The code is just: Code: [Select] echo $message; Hi There, I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side. Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense? Table is a standard table with 2 columns and 5 rows. Thanks Matt The below might be a noob question but, I concatenate two spaces in the below string $new_hebrew_date_string = $hebrewMonthName . ' ' . $hebrewDay . "%"; yet when I execute echo "<br />new_hebrew_date_string is $new_hebrew_date_string<br />"; printf("hebrew_date_string is: %s <br />", $new_hebrew_date_string); Only one space is output in between $hebrewMonthName and $hebrewDay regardless of how many spaces I pad the string with. Strangely enough, the string $new_hebrew_date_string is correctly padded w/spaces when I pass it as a parameter to a mySQL stored procedure. Any ideas anyone? Thank you. Hi all, I was wondering if it was possible and not too messy to have a single form page (html) and have it post to 2 or more PHP files? Surely this is something that is desirable and accomplished at some point, right? Thanks. Richard I need to be able to upload multiple files with the use of one form. Right now I have support for one file and it works great. I am stuck on what route I should take for times sake and reliability and functionality. Can I run each file on its own through the PHP script to upload the file; I would have to create a loop to run through the script as many times as there are files. OR Do I create new functionality and add the files through the use of an array? This is where I am getting the ARRAY idea: http://www.phpeasystep.com/phptu/2.html This is the PHP code that is submitting the image and uploading to file system. This is what I would use to loop through multiple files if I take the loop method. <? header("location: /classifieds/index.php"); echo '<html><center>'; //first lets upload any files that were selected// $date = date("m/d/y",time()); //check that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 350Kb $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 2500000)) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/uploads/'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { //strip off file path for $newname variable so path is not accessible via html// $tempnewname = explode('/', $newname); echo $tempnewname; $newname=$tempnewname[9].'/'.$tempnewname[10]; echo "It's done! The file has been saved as: ".$filename; } else { echo "Error: A problem occurred during file upload!"; } } else { //echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";// $timestampname = str_replace('.jpg', date('j-n-Y_g:i:s').'.jpg', (basename($_FILES['uploaded_file']['name']))); $path = dirname(__FILE__).'/uploads/'; $fullname = $path.$timestampname; //strip off file path for $newname variable so path is not accessible via html// $tempnewname = explode('/', $fullname); $newname=$tempnewname[7].'/'.$tempnewname[8]; $picname=$tempnewname[8]; ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))); } } else { echo "Error: Only .jpg images under 2.5MB are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?> Thanks for hte help -Beemer Hi, I'm having a bit of a problem sharing some variables I have across a few files. My first file (index.php) calls an ajax request for (display.php) and sends a few variables to it. All fine so far. display.php then does its thing and displays the content on index.php as it should. Now in display.php I need a variable to be passed back to index.php for use in a menu. I've tried setting a session variable in display.php but unfortunately this doesn't seem to work. I also can't use get or post as I don't want to refresh the page. Really scratching my head over this one! Edd Hi Guys, I have a HTML form which posts to a PHP mail script page. This data then emails to the company email address. I have two file attachments on my form: CV and Photo ID How do I integrate my php mail script to upload and then email these TWO files as TWO attachements on the email? $fileatt_cv $fileatt_id I have tried a few methods that I found on Google but they dont work Code: [Select] <?php // Grab Data from Form if(isset($_POST['submit'])) { // Personal Information $surname = mysql_real_escape_string($_POST['surname']); $firstname = mysql_real_escape_string($_POST['firstname']); $telephone = mysql_real_escape_string($_POST['telephone']); $mobile = mysql_real_escape_string($_POST['mobile']); $email = mysql_real_escape_string($_POST['email']); $address = mysql_real_escape_string($_POST['address']); $postcodep1 = mysql_real_escape_string($_POST['postcodep1']); $postcodep2 = mysql_real_escape_string($_POST['postcodep2']); $dob_dd = mysql_real_escape_string($_POST['dob_dd']); $dob_mm = mysql_real_escape_string($_POST['dob_mm']); $dob_yyyy = mysql_real_escape_string($_POST['dob_yyyy']); // Next of Kin $nextkinname = mysql_real_escape_string($_POST['nextkinname']); $nextkintel = mysql_real_escape_string($_POST['nextkintel']); // Availability $days_mon = mysql_real_escape_string($_POST['days_mon']); $days_tue = mysql_real_escape_string($_POST['days_tue']); $days_wed = mysql_real_escape_string($_POST['days_wed']); $days_thu = mysql_real_escape_string($_POST['days_thu']); $days_fri = mysql_real_escape_string($_POST['days_fri']); $days_sat = mysql_real_escape_string($_POST['days_sat']); $days_sun = mysql_real_escape_string($_POST['days_sun']); $availability_am = mysql_real_escape_string($_POST['availability_am']); $availability_pm = mysql_real_escape_string($_POST['availability_pm']); $availability_allday = mysql_real_escape_string($_POST['availability_allday']); $availability_requirements = mysql_real_escape_string($_POST['availability_requirements']); // Experience $experience = mysql_real_escape_string($_POST['experience']); // File Attachments $fileatt_cv = mysql_real_escape_string($_POST['fileatt_cv']); $fileatt_id = mysql_real_escape_string($_POST['fileatt_id']); // Rates $rate = mysql_real_escape_string($_POST['rate']); $rate_specific = mysql_real_escape_string($_POST['rate_specific']); // Employer Ref $employrefname = mysql_real_escape_string($_POST['employrefname']); $employrefcomp = mysql_real_escape_string($_POST['employrefcomp']); $employreftel = mysql_real_escape_string($_POST['employreftel']); $employrefadd = mysql_real_escape_string($_POST['employrefadd']); // Personal Ref $persrefname = mysql_real_escape_string($_POST['persrefname']); $persreftel = mysql_real_escape_string($_POST['persreftel']); $persrefadd = mysql_real_escape_string($_POST['persrefadd']); // Extra Information $allergy = mysql_real_escape_string($_POST['allergy']); $allergy_details = mysql_real_escape_string($_POST['allergy_details']); $drive = mysql_real_escape_string($_POST['drive']); $car = mysql_real_escape_string($_POST['car']); $criminal = mysql_real_escape_string($_POST['criminal']); $criminal_details = mysql_real_escape_string($_POST['criminal_details']); $howlongworkuk = mysql_real_escape_string($_POST['howlongworkuk']); $police_check = mysql_real_escape_string($_POST['police_check']); $right2work = mysql_real_escape_string($_POST['right2work']); $right2workna = mysql_real_escape_string($_POST['right2workna']); // Email Options $subject = "Test Company - Job Application"; $to = "test@test.com"; $mailheader = "From: $email" . "\r\n"; $mailheader .= 'MIME-Version: 1.0' . "\r\n"; $mailheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Applicants copy $mailheader .= "BCc: $email" . "\r\n"; // Message Content $body .= 'Message'; // End of Email Content > Display Message echo "Thank you. Your application was submitted to us successly. We review all applications carefully and we may contact you shortly."; // Attempt to Send Email mail($to, $subject, $body, $mailheader); } else { echo "Application Failed. Unfortunatley, there was a problem with your application and it was not submitted. Please try again later or alternativley please contact us."; } ?> Thanks in advanced. Good day all. I am looking for guidence. I am using phpexcell to format an excell file. all working 100% What should i be looking to do when i want to edit and format multiple files in a directory. about 200 excell documents all the same and with same formatting? Found this code for reading, but lets say row c3:i3 i want bold and size 14 in all the excell files . . . $path = "..."; ///the folder path $theFilePath = ""; $theFileName = glob ($path . "*.xls"); //Read more than one file here for($j = 0; $j< count($theFileName); $j++) { $theFilePath = $theFileName[$j]; $excel = new Spreadsheet_Excel_Reader(); $excel->setOutputEncoding('CP1251'); $excel->setUTFEncoder('mb_convert_encoding'); error_reporting(E_ALL ^ E_NOTICE); //echo $theFileName[$j];; echo "<br />"; echo $theFilePath; echo "<br />"; $excel->read($theFilePath); . . .// Do what u want display here }
Good day.
I have just written my first php phpexcell file importing into mysql without errors. now my next step is to try and read multiple excell files in a directory " files are same format" and import into mysql.
Heres my code so far.
<?php $db_host = "localhost";$db_user = "root";$db_pass = "";$db_name ="kk";$db_table = "test"; require '/Classes/PHPExcel.php'; require_once '/Classes/PHPExcel/IOFactory.php'; $objPHPExcel = PHPExcel_IOFactory::load('Amersfoort_WR.xlsx'); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $worksheetTitle = $worksheet->getTitle(); $highestRow = $worksheet->getHighestRow(); // e.g. 10 $highestColumn = $worksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); $nrColumns = ord($highestColumn) - 64; echo "File ".$worksheetTitle." has "; echo $nrColumns . ' columns'; echo ' y ' . $highestRow . ' rows.'; echo "$cellValue"; $link = mysql_connect($db_host,$db_user,$db_pass); if(!$link) die ('Could not connect to database: '.mysql_error()); mysql_select_db($db_name,$link); for ($row = 2; $row <= $highestRow; ++ $row) { $val=array(); for ($col = 0; $col < $highestColumnIndex; ++ $col) { $cell = $worksheet->getCellByColumnAndRow($col, $row); $val[] = $cell->getValue(); } $sql = "insert into test (F1, F2, F3, F4) values('".$val['0']."', '".$val['1']."', '".$val['2']."','".$val['3']."')"; mysql_query($sql); } } mysql_close($link); ?> hello! in my header.php file i have the following line of code: Code: [Select] <link rel="stylesheet" href="<?php echo $pageCSS; ?>"> in the document proper, i have the following at the top of the page: Code: [Select] <?php $pageCSS="_css/compare.css"; ?> this works as expected and it's clean and neat. what i want to know is how i can adapt this to pass MULTIPLE JavaScript files through it. would it be best to pass an array of files and then step through the array? would be nice to be able to pass a simple comma-delimited list. any help would be appreciated. WR! |