PHP - Download Multiple Files Using One Button
Hi guys i am kinda stuck at a part where i want a download button to prompt out two download windows in a click. Currently i am able to prompt out one download window only. I have tried putting another header line of Content Disposition but it doesn't work..i will appreciate if you guys can help me out, thanks!
The desired scenario will be WinSCP.exe download prompt will appear first, follow by auditgroup.bat $file1 = "WinSCP.exe"; $file = "auditgroup.bat"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file); Similar TutorialsHi Guys I trying to download files and I have this error message, hopelly you guys can help me please
Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 14 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 16 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 17 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 18 This is the code I use to force the download <?php include('core/inc/init.inc.php'); if(isset($_GET['file_id'])) { $file_id=(int)$_GET['file_id']; $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id"); if(mysql_num_rows($file)!=1){ echo'Invalid file Id'; }else{ $row=mysql_fetch_assoc($file); if ($row['file_expiry']<time()){ echo'This file has expired'; }else{ $path="core/files/{$row['$file_name']}"; header('Content-Type:application/octet-stream'); header('Content-Description:File Transfer'); header('Content-Transfer-Encoding:binary'); header("Content-Disposition:attachment;filename=\"{$row['file_name']}\""); header('Content-Length:'.filesize($path)); readfile($path); } } } ?>Thank you for your help..... I've searched the forum, and haven't yet found what I need. I have a long list of PDF files: http://www.iampeth.com/vintage_magazines.php How can I track the number of downloads for each file? Hi PHP Community, I have this class in my DOCMAN script and would like to add aditional functionality to watermark existing PDF files: Code: [Select] class DOCMAN_File { /** * @access public * @var string */ var $path = null; /** * @access public * @var string */ var $name = null; /** * @access public * @var string */ var $mime = null; /** * @access public * @var string */ var $ext = null; /** * @access public * @var string */ var $size = null; /** * @access public * @var string */ var $date = null; /** * @access private * @var string */ var $_err = null; /** * @access private * @var boolean */ var $_isLink; function DOCMAN_File($name, $path) { $path = mosPathName( $path ); if (!is_dir( $path )) { $path = dirname( $path ); } $this->name = trim($name); $this->path = $path; if( strcasecmp( substr( $this->name , 0, _DM_DOCUMENT_LINK_LNG ) , _DM_DOCUMENT_LINK )==0){ $this->_isLink = true; $this->size = 0; $this->mime = 'link'; }else{ $this->_isLink = false; $this->size = filesize($this->path."/".$this->name); $this->mime = DOCMAN_MIME_Magic::filenameToMIME($this->name, false); } $this->ext = $this->getExtension(); } /** * Download or view a file from the server * @desc This is the function handling files downloading using HTTP protocol * @param void * @return void */ function download() { $user_agent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT; //Fixed [#2534] clean all output buffers (needs PHP > 4.2.0) /* while (ob_get_level()) { * ob_end_clean(); }*/ // Fix [3164] while (@ob_end_clean()); if( $this->_isLink ){ header( "Location: " . substr( $this->name , 6 ) ); return; } $fsize = filesize($this->path."/".$this->name); $mod_date = date('r', filemtime( $this->path.'/'.$this->name ) ); $cont_dis = 'attachment;'; if(isset($_REQUEST['mode'])) $cont_dis = ($_REQUEST['mode'] == 'view') ? 'inline;' : 'attachment;'; header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Expires: 0"); header("Content-Transfer-Encoding: binary"); header('Content-Disposition:' . $cont_dis .'";' . ' filename="' . $this->name . '";' . ' modification-date="' . $mod_date . '";' . ' size=' . $fsize .';' ); //RFC2183 header("Content-Location: ". $this->path . '/' . $this->name ); header("Content-Type: " . $this->mime ); // MIME type header("Content-Length: " . $fsize); // No encoding - we aren't using compression... (RFC1945) // header("Content-Encoding: "); readfile($this->path."/".$this->name); // The caller MUST 'die();' } function exists() { if( $this->_isLink ){ return true; } return file_exists($this->path."/".$this->name); } function isLink(){ return $this->_isLink ; } /** * Get file size * * @desc Gets the file size and convert it to friendly format * @param void * @return string Returns filesize in a friendly format. */ function getSize() { if( $this->_isLink ){ return 'Link'; } $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; $size = $this->size; if ($size) { if ($size < $kb) { $file_size = "$size Bytes"; } elseif ($size < $mb) { $final = round($size/$kb,2); $file_size = "$final KB"; } elseif ($size < $gb) { $final = round($size/$mb,2); $file_size = "$final MB"; } elseif($size < $tb) { $final = round($size/$gb,2); $file_size = "$final GB"; } else { $final = round($size/$tb,2); $file_size = "$final TB"; } } else { if( $size == 0 ) $file_size = "Empty!"; else $file_size = "ERROR"; } return $file_size; } /** * @desc Gets the extension of a file * @return string The file extension */ function getExtension() { if( $this->_isLink ) return "lnk"; $dotpos = strrpos($this->name, "."); if ($dotpos < 1) return "unk"; return substr($this->name, $dotpos + 1); } function getDate($type = 'm') { if( $this->_isLink ){ return ""; } $date = ''; switch($type) { case 'm' : $date = filemtime($this->path."/".$this->name); break; case 'a' : $date = fileatime($this->path."/".$this->name); break; case 'c' : $date = filectime($this->path."/".$this->name); break; } return date ("m.d.y - H:i:s", mosFormatDate($date)); } } I found this function on the net and it works fast. But because I'm newbie I have problem in implementing it correctly to class: Code: [Select] function WaterMark($filename){ $tempfile=tempnam('/path/to/directory/tmp,'temp.pdf'); $watermark = "/path/to/directory/htdocs/components/com_docman/includes_frontend/water.pdf"; system("pdftk $filename stamp $watermark output $tempfile dont_ask", $errcode); if (!$errcode && $ih=fopen($tempfile, 'r')) { header('Content-Type: application/pdf'); fpassthru($ih); fclose($ih); } else { print "Whoops"; } unlink($tempfile); } Here is frontend use of class. Code: [Select] $downloadDoc = new DOCMAN_File($document->dmfilename,$_DOCMAN->getCfg('dmpath')); $downloadDoc->download(); For now I only managed to get it working to watermark PDF file for view mode but not before download mode as attachment. Function is working fine by itself but not when integrated in class. I'm getting really frustrated . Please help me!?! Thank you everybody. Al Hey guys, im starting out on my php journey with a small question. I have a small uploading site and i want to allow php uploads. Once uploaded, you get a direct upload link, and i want the file to download, rather than execute. How can this be done? Thanks! Hi, how much bandwidth is used for 1000 downloads per day or for each download? Is it safe to have no download limits? Thanks
I have a Joomla website having one folder for audio files in it and their links are saved in database. Now I want to show two calendars to the user at front end, so that they can choose that from when to from he want to download the audio files? for e.g he can select june-2-2014 in one calendar and august-2-2014 in second calendar, now on clicking download button the files residing between the two specific dates must get archived into one zip file and then start downloading... i have a reference link for creating a zip and downloading the zip :http://coursesweb.ne...-archive-php_cs now i am stuck that how to get the selection of user from calendar , save it into the array , and from the array get the files from the folder matching the array indexes and then zip , download them. please tell me how to achieve this task ? I have the following code, but wish to allow admin members to download the short WMV video without having the page reload. My page can have anything to to 20 videos on the page. I can place a button there but how to I get the video files to download and not play when clicked. Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Admin</title> <link href="style2010.css" rel="stylesheet" type="text/css"> </head> <body style="width:1000px; width: 50%; margin-left: auto; margin-right: auto;"> <div style="width:1000px; padding-right: 3px; padding-left: 3px; height:100%; min-height: 500px;"> <div align="center"><h2>Admin</h2><br /></div> <div style="float: left; padding-left: 5px;"> <form name="delete" method="post" action=""> <div align="center" style="float: left; padding: 0 10px 50px 10px;"> <object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="MediaPlayer1" standby="Loading Windows Media Player components..." width="300" height="300"> <PARAM NAME="url" value="67.wmv" /> <param name="src" value="67.wmv" /> <param name="showcontrols" value="true" /> <param name="autostart" value="false" /> <!--[if !IE]>--> <object type="video/x-ms-wmv" data="67.wmv" width="300" height="300"> <param name="src" value="67.wmv" /> <param name="autostart" value="false" /> <param name="controller" value="true" /> </object> <!--<![endif]--> </object> <br />67.wmv<br />Delete above file? <input name="67---wmv" type="checkbox" value="delete"> </div> <br clear="all"/><input type="submit" name="Delete Selected" value="Delete Selected"> </form> <br /><br /> </div> </div> <br style="clear:both" /> </body> </html> I've added a download button to all of my posts using custom fields in wordpress. I know there is an easier way just not sure how. Right now I have to add the custom field on each post, instead I'd like to just have a download button (with css) automatically on all posts (download button will be going to the same url on each post). My current code Code: [Select] <div id="downloadbutton"> <?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?> <a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"<img src="http://www.MYSITE.com/images/downloadbutton.png" border="0"></a> <?php } ?> </div> Appreciate the help! 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 }
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. 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 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 want to read multiple .txt files and then if an action requires select one. Quote <? // /home/person-mike.txt // /home/person-sarah.txt // /home/person-paul.txt while ($row = sqlite_fetch_array($result)) { $name = $row['name']; $filename = "/home/person-$name.txt"; $handle = fopen($filename, "r"); $sendrequest = fread($handle, filesize($filename)); fclose($handle); } ?> <? if ( $client == "sarah" ) { echo "$sendrequest[sarah]"; ?> How do I do the last bit to have a variable like $sendrequest[sarah] 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! I have this code and its downloading file nicely. But I want to show a progress bar while downloading file from external server. My existing code shows progress bar but its not effective (ex. if i try to download two media file, one video and another audio, and video size is larger than audio size the audio finishes first and the progress bar shows 100% also suddenly it drops to 50% as the video is still downloading ). I mean it actually shows two progress and I need one. If I could get average percentage value of two progress that would be better. Any suggestion regarding this will be greatly appreciated. <?php set_time_limit ( 0 ); function define_progress_callback($i) { global $conn; curl_setopt($conn[$i], CURLOPT_PROGRESSFUNCTION, function ($resource,$download_size, $downloaded, $upload_size, $uploaded) { if($download_size > 0) $progress = round($downloaded / $download_size * 100); echo '<script language="javascript">$(".loader").loader("setProgress", '.$progress.');</script>'; echo str_pad("",1024," "); flush(); usleep(20000); }); } $urls = array("http://example.com/file.mp3", "http:/example.com/file.mp4"); $save_to='./tmp/'; $conn = array(); $fp = array(); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $g = $save_to . basename($url); $conn[$i]=curl_init($url); $fp[$i]=fopen ($g, "wb"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // No certificate curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]); curl_setopt ($conn[$i], CURLOPT_HEADER ,0); curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,60); curl_setopt ($conn[$i], CURLOPT_MAXCONNECTS, 10); curl_setopt($conn[$i], CURLOPT_NOPROGRESS, false); define_progress_callback($i); curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); fclose($fp[$i]); } curl_multi_close($mh); ?> Edited by requinix, 18 January 2015 - 08:16 AM. no code tags meant auto-embedding of mp3 I am trying to convert 6 files into a single 1 php file. I have attached the original files. I need help because I don't know where I am going wrong. this what I have done so far : <?php session_start(); if ($_SESSION['ON'] =="FALSE" || $_SESSION['ON']==null) { header( 'Location: index.php?error=invalid-login' ); session_unset(); session_destroy(); exit(); } ?> <html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>LOGIN WEB SESSION</title> <link rel="stylesheet" type="text/css" href="loginsession.css" /> </head> <body> <?php // If the step is one, show the correct form // if ($step == 0) { echo '<form action="index.php?step=2" method="post"> <table> <tr><td width="100">Username:</td><td width="200"><input type="text" name="username"></td></tr> <tr><td width="100">Password:</td><td width="200"><input type="password" name="password"></td></tr> <tr><td colspan="2" align="center"><input type="submit" value="Login"></td></tr> </table> </form>'; } else if ($step == 1) { // Create the step 2 section of the page // function clean($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $user = clean($_POST['username']); $pass = clean($_POST['password']); if ($user == "webdeveloper" && $pass == "master") { session_start(); $_SESSION['username'] = $user; $_SESSION['password'] = $pass; $_SESSION['ON']="TRUE"; $lifetime=600; setcookie(session_name(),session_id(),time()+$lifetime); header( 'Location: index.php?step=2' ) ; exit(); } else { header( 'Location: index.php' ); session_destroy(); exit(); } } else if ($step == 2) <div>LOGIN WELCOME</div> <div> HERE IS YOUR USER DATA:<br /> <label class="data">username:'; <?php echo $_SESSION['username'] ?> <br> password: <?php echo $_SESSION['password'] ?> <br></label> HERE IS YOUR SESSION DATA:<br /> <label class="data"> <?php echo (session_name().": ".session_id()) ?><br> <?php echo ("SESSION DATA: ".session_encode() )?> </label> </div>index.php?step=3">Logoff</a></div> } else if ($step == 3) { // Create the step 4 section of the page // header( 'Location: index.php' ); session_start(); session_unset(); session_destroy(); exit(); } ?> </body> </html> 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); ?> 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>'; ?> I have looked around all overr, but cant find what im looking for. Everything I have found is about uploading multile files, what I need to do is upload one file and copy it so there is 3 files. Here is an example of what I need to accomplish. Upload file picture1.jpg From picture1.jpg create 3 files - smallimage_picture1.jpg, largeimage_picture1.jpg & smallimage_picture1_thumb.jpg Each file will need to be copied to a /products directory and also an entry for each file name placed in mysql database table. I don't think this is as simple as it sounds to do in PHP, but i am very willing to learn so if anyone knows of a good tutorial that get get me started that would be super. regards DB |