PHP - Dir Of Unix Server Sorted By File Name
Hi,
I have switched to a unix server from a windows one and my dir.php now displays in date order which makes things very hard to find Below is the code I use, can anyone tell me what to put, and where ? to make it sort by file name, or point me to a freeware script that has already invented the wheel so to speak. <?php function humansize($size) { $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if($size < $kb) return $size."B"; else if($size < $mb) return round($size/$kb,0)."KB"; else if($size < $gb) return round($size/$mb,0)."MB"; else if($size < $tb) return round($size/$gb,0)."GB"; else return round($size/$tb,2)."TB"; } $path= dirname($_SERVER['SCRIPT_FILENAME']); ?> <h3>Files in <?php print $path; ?>:</h3> <ul> <?php $d = dir($path); $icon = ''; while (false !== ($entry = $d->read())) { if ( substr($entry, 0, 1)=='.' ) continue; $size = filesize($path.'/'.$entry); $humansize = humansize($size); $dotpos = strrpos($entry, '.'); if ($dotpos) { $ext = substr($entry, $dotpos+1); if ($ext === 'jpeg' || $ext === 'gif' || $ext === 'png') { $icon = "<img src='$entry' style='width: 48px; height: auto; vertical-align: text-top;' alt='icon' title='$entry' />"; } } print "<li><a href='$entry'>$entry</a> ($humansize) $icon</li>\n"; $icon= ''; } $d->close(); ?> Please help an old fellow who should know better Regards Topshed Similar TutorialsI have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? Hey. I am wanting to move a couple of files from my current server to another. If i am uploading the file this is fine but if it is already on the server then im not sure how to move it. When uploading I can just use ftp_put($conn_id, $destination_file, $myFile, FTP_BINARY); What i need to do is figure out how to get a hold of the file and store it in $myFile then this would work fine. Is this possible? Cheers Anyone know how I can print a file (specifically a PDF) that is stored on the server to the clients computer with a button? I don't want them to be able to view it, just print it. I've done some research and understand that there is no way to print directly without popping up the Windows Print dialog. And that is fine. I just want them to print this file, but not no where it is or be able to type in a URL to access it. Thanks Mike Hello, I have a msql table that has data input every hour of every day, so each date is entered 24 times next to the hour field as seen below the PHP... How do I get the information between a daterange that comes from the datepickers (start and end date) to show values of Power, Volt, and current for each day and hour in a report ? Here is what I have written, but I think the time, or multiple of same dates is stopping it from working... <?php if(isset($_POST['start1']) && isset($_POST['end1'])){ $start = (isset($_POST['start1'])) ? date("Y-m-d",strtotime($_POST['start1'])) : date("Y-m-d"); $end = (isset($_POST['end1'])) ? date("Y-m-d",strtotime($_POST['end1'])) : date("Y-m-d"); $con = mysql_connect('xxxxxx', 'xxxxxx', 'xxxxxxxxxx'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT * FROM report WHERE date BETWEEN '$start' AND '$end'"; echo "<table border='1'> <tr> <th>Date</th> <th>Hour</th> <th>Power</th> <th>Volt</th> <th>Current</th> </tr>"; $res = mysql_query($sql) or die(__LINE__.' '.$sql.' '.mysql_error()); while($row = mysql_fetch_array($res)){ echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Time'] . "</td>"; echo "<td>" . $row['Power'] . "</td>"; echo "<td>" . $row['Volt'] . "</td>"; echo "<td>" . $row['Current'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); } ?> The DATE is a DATE, the TIME is TIME, the power,volt, current are FLOAT unit ID | Date | Time | Power | Volts | Current | 1 10/15/2010 21:00:00 0 220 100 1 10/15/2010 22:00:00 0 220 100 1 10/15/2010 23:00:00 0 220 100 1 10/16/2010 00:00:00 0 220 100 1 10/16/2010 01:00:00 0 220 100 1 10/16/2010 02:00:00 0 220 100 1 10/16/2010 03:00:00 0 220 100 1 10/16/2010 04:00:00 0 220 100 1 10/16/2010 05:00:00 245 220 100 1 10/16/2010 06:00:00 360 220 100 1 10/16/2010 07:00:00 596 220 100 1 10/16/2010 08:00:00 1567 220 100 1 10/16/2010 09:00:00 1568 220 100 1 10/16/2010 10:00:00 1598 220 100 1 10/16/2010 11:00:00 1642 220 100 1 10/16/2010 12:00:00 1658 220 100 1 10/16/2010 13:00:00 1664 220 100 1 10/16/2010 14:00:00 1598 220 100 1 10/16/2010 15:00:00 1527 220 100 1 10/16/2010 16:00:00 980 220 100 1 10/16/2010 17:00:00 410 220 100 1 10/16/2010 18:00:00 208 220 100 1 10/16/2010 19:00:00 0 220 100 1 10/16/2010 20:00:00 0 220 100 1 10/16/2010 21:00:00 0 220 100 1 10/16/2010 22:00:00 0 220 100 1 10/16/2010 23:00:00 0 220 100 1 10/17/2010 00:00:00 0 220 100 1 10/17/2010 01:00:00 0 220 100 1 10/17/2010 02:00:00 0 220 100 I have a table with two columns. The first is an id column, set to be my primary key, non null, unique, int, and auto increment. The second is a varchar(10) column. Very strangely, when I set the varchar(10) column to unique, and try to edit the table in workbench, the table is automatically ordered by my varchar column, and not my id (primary key column). If I mark the varchar(10) column as not unique, data is ordered by the primary key, as expected. What is going on here? I expected the primary key to be default ordering for the table. I hope to not use an ORDER BY clause.
Edited by E_Leeder, 29 November 2014 - 02:14 AM. I am trying create a webpage that will automatically display new agendas as I add them to the server. I do this right now but I have to put the agendas in the agendas and the board folders. I want to simplify this by only putting the agendas in the board folder. My code kinda works but the results aren't sorted correctly. My code scans the current directory for the list of current boards. The arrary_diff removes the boards that are no longer active. It then appends the current year to the folder information. Next I glob all of the Agendas in the various directories and then I sort the resulting glob. Finally I print the results which are out of date order. I tried sort(basename($agendas)) but that is not valid syntax for sort. Then I was thinking of a 2 dimension array, the first element is the filename, the second element is the fullpath. Then I sort on the first element but I haven't figured out how to get that to work. So I went back to my first code and I am asking what did I do wrong? Am I on the right track to do what I want? The directory structure is like this: Array ( [0] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/01-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [1] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/02-24-2021_Board_of_Zoning_Appeals_Agenda.pdf [2] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/03-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [3] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf [4] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/01-24-2021_EDC_Agenda.pdf [5] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/02-21-2021_EDC_Agenda.pdf [6] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/03-21-2021_EDC_Agenda.pdf [7] => ./meeting-minutes-agendas/Park_Board/2021/01-21-2021_Park_Board_Agenda.pdf [8] => ./meeting-minutes-agendas/Park_Board/2021/02-18-2021_Park_Board_Agenda.pdf [9] => ./meeting-minutes-agendas/Park_Board/2021/03-18-2021_Park_Board_Agenda.pdf [10] => ./meeting-minutes-agendas/Park_Board/2021/03-27-2021_Park_Board_Agenda.pdf [11] => ./meeting-minutes-agendas/Park_Board/2021/04-22-2021_Park_Board_Agenda.pdf [12] => ./meeting-minutes-agendas/Plan_Commission/2021/01-07-2021_Plan_Commission_Agenda.pdf [13] => ./meeting-minutes-agendas/Plan_Commission/2021/01-21-2021_Plan_Commission_Agenda.pdf [14] => ./meeting-minutes-agendas/Plan_Commission/2021/02-04-2021_Plan_Commission_Agenda.pdf [15] => ./meeting-minutes-agendas/Plan_Commission/2021/02-18-2021_Plan_Commission_Agenda.pdf [16] => ./meeting-minutes-agendas/Plan_Commission/2021/03-04-2021_Plan_Commission_Agenda.pdf [17] => ./meeting-minutes-agendas/Plan_Commission/2021/03-18-2021_Plan_Commission_Agenda.pdf [18] => ./meeting-minutes-agendas/Plan_Commission/2021/04-08-2021_Plan_Commission_Agenda.pdf [19] => ./meeting-minutes-agendas/Plan_Commission/2021/04-22-2021_Plan_Commission_Agenda.pdf [20] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/01-17-2021_RDC_Agenda.pdf [21] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/02-14-2021_RDC_Agenda.pdf [22] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/03-14-2021_RDC_Agenda.pdf [23] => ./meeting-minutes-agendas/Safety_Board/2021/01-08-2021_Safety_Board_Agenda.pdf [24] => ./meeting-minutes-agendas/Safety_Board/2021/02-16-2021_Safety_Board_Agenda.pdf [25] => ./meeting-minutes-agendas/Safety_Board/2021/03-16-2021_Safety_Board_Agenda.pdf [26] => ./meeting-minutes-agendas/Safety_Board/2021/04-22-2021_Safety_Board_Agenda.pdf [27] => ./meeting-minutes-agendas/Sanitary_District/2021/01-19-2021_Sanitary_District_Agenda.pdf [28] => ./meeting-minutes-agendas/Sanitary_District/2021/02-16-2021_Sanitary_District_Agenda.pdf [29] => ./meeting-minutes-agendas/Sanitary_District/2021/03-16-2021_Sanitary_District_Agenda.pdf [30] => ./meeting-minutes-agendas/Sanitary_District/2021/03-23-2021_Sanitary_District_Agenda.pdf [31] => ./meeting-minutes-agendas/Sanitary_District/2021/03-31-2021_Sanitary_District_Agenda.pdf [32] => ./meeting-minutes-agendas/Sanitary_District/2021/04-20-2021_Sanitary_District_Agenda.pdf [33] => ./meeting-minutes-agendas/Town_Council/2021/01-13-2021_Town_Council_Agenda.pdf [34] => ./meeting-minutes-agendas/Town_Council/2021/01-27-2021_Town_Council_Agenda.pdf [35] => ./meeting-minutes-agendas/Town_Council/2021/02-02-2021_Town_Council_Agenda.pdf [36] => ./meeting-minutes-agendas/Town_Council/2021/02-24-2021_Town_Council_Agenda.pdf [37] => ./meeting-minutes-agendas/Town_Council/2021/03-03-2021_Town_Council_Agenda.pdf [38] => ./meeting-minutes-agendas/Town_Council/2021/03-24-2021_Town_Council_Agenda.pdf [39] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Special_Meeting_Agenda.pdf [40] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Study_Session_Agenda.pdf [41] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-07-2021_Waterwork_Board_Agenda.pdf [42] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-19-2021_Waterworks_Board_Agenda.pdf [43] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-28-2021_Waterworks_Board_Agenda.pdf [44] => ./meeting-minutes-agendas/Waterworks_Board/2021/02-16-2021_Waterworks_Board_Agenda.pdf [45] => ./meeting-minutes-agendas/Waterworks_Board/2021/03-16-2021_Waterworks_Board_Agenda.pdf [46] => ./meeting-minutes-agendas/Waterworks_Board/2021/04-20-2021_Waterworks_Board_Agenda.pdf ) What I get is
04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf when it should be:
04-20-2021_Sanitary_District_Agenda.pdf <?php $files = array_diff(scandir('./meeting-minutes-agendas'), array('..', '.', 'Default.php', 'Agendas', 'Police_Commission', 'Utility_Board')); sort($files); foreach($files as &$file) { $file = $file . "/" . date("Y"); } unset($file); $agendas = array(); foreach($files as $file) { $temp = glob('./meeting-minutes-agendas/'. $file . "/*Agenda.pdf"); $agendas = array_merge($agendas, $temp); } unset($files); unset($temp); sort($file); foreach($agendas as $file) { $filedate = str_replace('-', '/',substr(basename($file),0,10)); if (strtotime($filedate) >= strtotime(date('m/d/Y'))) { echo "<a href='"; echo $file; echo "'>"; $file = str_replace('.php', '', $file); echo basename($file); echo "</a><br>\n"; } } unset($file); ?>
i've been able to load up a csv file and display it as a html table but what i'm having trouble with is sorting it out with headings a to z but what i am trying to do is have 4 columns like this. Surgestions about how to do what im after i was hoping i could span the say A across all columns and centering them in the future also but thats not really the problem mainly the getting the array of the csv file and code right iguess. any help would be appreciated Code: [Select] <table> <tr> <th>A</th> </tr> <tr> <td>Apple1</td> <td>Apple2</td> <td>Apple3</td> <td>Apple4</td> <td>Apple5</td> <td>Apple6</td> </tr> <tr> <th>B</th> </tr> <td>Banana1</td> <td>Banana2</td> <td>Banana3</td> <td>Banana4</td> <td>Banana5</td> <td>Banana6</td> <tr> <th>C</th> </tr> <td>Cold1</td> <td>Cold2</td> <td>Cold3</td> <td>Cold4</td> <td>Cold5</td> <td>Cold6</td> </table> This is the code for inputting of the csv file i also have some other code i was wanting to use for the sorting of the array data from the csv file i'll past below.... Quote <?php $file = "widgets.csv"; $delimiter = ","; $enclosure = '"'; $column = array("", "", "", ""); @$fp = fopen($file, "r") or die("Could not open file for reading"); while (!feof($fp)) { $tmpstr = fgets($fp, 100); $line[] = preg_replace("/r/", "", $tmpstr); } for ($i=0; $i < count($line); $i++) { $line[$i] = explode($delimiter, $line[$i]); } ?> <html> <head> <title>Albert's Delimited Text to HTML Table Converter</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="1" cellpadding="5" cellspacing="0"> <tr> <?php for ($i=0; $i<count($column); $i++) echo "<th>".$column[$i]."</th>"; ?> </tr> <?php for ($i=0; $i < count($line); $i++) { echo "<tr>"; for ($j=0; $j < count($line[$i]); $j++) { echo "<td>".$line[$i][$j]."</td>"; } echo "</tr>"; } fclose($fp); ?> </table> </body> </html> Heres the code for the sorting of the table data from the array Quote <?php echo "QUERY_STRING is ".$_SERVER['QUERY_STRING']."<p>"; $rev=1; $sortby=0; if(isset($_GET['sortby']))$sortby = $_GET['sortby']; if(isset($_GET['rev']))$rev = $_GET['rev']; //Open and read CSV file example has four columns $i=-1; $ff=fopen('widgets2.csv','r') or die("Can't open file"); while(!feof($ff)){ $i++; $Data[$i]=fgetcsv($ff,1024); } //Make columns sortable for each sortable column foreach ($Data as $key => $row) { $One[$key] = $row[0]; // could be $row['Colname'] $Two[$key] = $row[1]; //numeric example $Three[$key] = $row[2]; $Four[$key] = $row[3];} //numeric example //Case Statements for Sorting switch ($sortby){ case "0": if($rev=="1")array_multisort($One, SORT_NUMERIC, $Data); //SORT_NUMERIC optional else array_multisort($One, SORT_NUMERIC, SORT_DESC,$Data); $rev=$rev*-1; break; case "1": if($rev=="1")array_multisort($Two, $Data); else array_multisort($Two, SORT_DESC, $Data); $rev=$rev*-1; break; case "2": if($rev=="1")array_multisort($Three, SORT_NUMERIC, $Data); else array_multisort($Three, SORT_NUMERIC, SORT_DESC,$Data); $rev=$rev*-1; break; case "3": if($rev=="1")array_multisort($Four, $Data); else array_multisort($Four, SORT_DESC, $Data); $rev=$rev*-1; break;} echo ("<table border=2>"); //$rev is reverse variable echo ("<th><a href=\"SortTable.php?sortby=0&rev=$rev\" title=\"Click to Sort/Reverse sort\">One</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=1&rev=$rev\" title=\"Click to Sort/Reverse sort\">Two</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=2&rev=$rev\" title=\"Click to Sort/Reverse sort\">Three</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=3&rev=$rev\" title=\"Click to Sort/Reverse sort\">Four</a></th>"); $i=0; foreach($Data as $NewDat){ if($NewDat[0]!=""){ //error trap $str="<tr>"; foreach($NewDat as $field)$str.="<td>$field</td>"; $str.="</td>\n"; echo $str;}} fclose($ff); echo "</table>"; Hello, Ive got a script that downloads a file to my server. I want to be able to download a file from a site such as FileServe using my premium details. Ive tried http://username:password@fileserve.com/file.rar but that dosent work, It just downloads a tiny small 30kb file. Is there a way i can set a cookie or somthing so my script has access to download file using my premium account? Thanks in advance Hello all, I need to basically run a PHP file stored on a server when other specific files are modified, but only then. Is this possible with PHP? Thank you for the feedback, I have a script that uploads my file, but this script requires apache. I want to get this file onto my other server that's running nginx. Is there a way for PHP to write a file to nginx? Alternatively, is there a way for PHP to copy a file from one server to another? Because that will work as well. How do I do this? Hi I have a form which is used to upload files to my server, now i need to move files to another server as soon they are uploaded, but move_uploaded_file will work with local server where form has been submitted. i was thinking to add some ftp functions to upload that file to remote server but is there any better way? that user dont notice ftp connection timing. i wants to use less ftp connections and user should not notice delay timing for image upload. Thanks for any suggestion. i am making song site i want to upload songs files on another instread on which m running my script for uploading songs and adding information in data... mean want to know is there any function or method that i upload files through the panel of www.site1.com and my files upload on an other server www.site2.com. which code i have to write for doing this Hello all. I have a script that exports data from mysql to a csv file. Everything works great. However, I do not know how to save the csv file to the server. Does anyone have any ideas how I would do that? The script is below. Thanks for all help! Code: [Select] <?php $host = 'localhost'; $user = ''; $pass = ''; $db = ''; $table = ''; $file = 'export'; function escape_csv_value($value) { $value = str_replace('"', '""', $value); // First off escape all " and make them "" if(preg_match('/,/', $value) or preg_match("/n/", $value) or preg_match('/"/', $value)) { // Check if I have any commas or new lines return '"'.$value.'"'; // If I have new lines or commas escape them } else { return $value; // If no new lines or commas just return the value } } $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].", "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= escape_csv_value($rowr[$j]).','; //$csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); //header( "Content-Type: application/save-as" ); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: attachment; filename=".$filename.".csv"); //header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Hello There , I want to download a file from the server to the computer . How can i do this ?? i found out this code: header("Content-type: image/jpg"); header("Content-Disposition: attachment; filename=test.jpg"); the problem is , what i get is the file that the code was executed from saved in the .jpg format. how can i direct to a specified path to select a certain file then download it . example let's say i have a folder that contains 2 files: download.php and image.jpg how can i download the image.jpg from the server with the Save As window?? Thank You Is it possible to allow a script running on another server to write/read a specific file on my server? I can set file permissions, but not having any luck with file paths due to php5 blocking http:// urls. Hi, I have a form where a user selects a file to attach to the email. At the moment when you select a file it uploads from the user device. How do i change this so that a user can attach a file from a folder on the server. For example the folder name is uploadinvoice so when the user selects the browse button to attach a file it opens up the uploadinvoice folder on the server so the user can select the file from there ?
Thanks
coding i have at moment function ValidateEmail($email) { $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i'; return preg_match($pattern, $email); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1') { $mailto = $_POST['youremail']; $mailfrom = isset($_POST['myemail']) ? $_POST['myemail'] : $mailto; $subject = 'Message'; $message = 'Message'; $success_url = './test.php'; $error_url = ''; $eol = "\n"; $error = ''; $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response"); $boundary = md5(uniqid(time())); $header = 'From: '.$mailfrom.$eol; $header .= 'Reply-To: '.$mailfrom.$eol; $header .= 'MIME-Version: 1.0'.$eol; $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol; $header .= 'X-Mailer: PHP v'.phpversion().$eol; try { if (!ValidateEmail($mailfrom)) { $error .= "The specified email address (" . $mailfrom . ") is invalid!\n<br>"; throw new Exception($error); } $message .= $eol; foreach ($_POST as $key => $value) { if (!in_array(strtolower($key), $internalfields)) { if (!is_array($value)) { $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol; } else { $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol; } } } $body = 'This is a multi-part message in MIME format.'.$eol.$eol; $body .= '--'.$boundary.$eol; $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol; $body .= 'Content-Transfer-Encoding: 8bit'.$eol; $body .= $eol.stripslashes($message).$eol; if (!empty($_FILES)) { foreach ($_FILES as $key => $value) { if ($_FILES[$key]['error'] == 0) { $body .= '--'.$boundary.$eol; $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol; $body .= 'Content-Transfer-Encoding: base64'.$eol; $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol; $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol; } } } $body .= '--'.$boundary.'--'.$eol; if ($mailto != '') { mail($mailto, $subject, $body, $header); } header('Location: '.$success_url); } catch (Exception $e) { $errorcode = file_get_contents($error_url); $replace = "##error##"; $errorcode = str_replace($replace, $e->getMessage(), $errorcode); echo $errorcode; } exit;
} A beginner question.. I have tried "isset" but it aint working.. I wonder what PHP function to use to check if a user actually put a file to be uploaded on the server. A validation just in case a user just click the submit button w/out even choosing a file first. I have this code but it aint working... Code: [Select] <?php if(isset($_POST['submit'])) { if(isset($_FILES['uploaded_file'])) { echo "<span class=\"error_validation\">You haven't choose a logo to upload!<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } else { if($_FILES['uploaded_file']["type"] == "image/gif") { $target_path = "logo/"; $target_path = $target_path. basename('matzhee_logo.gif'); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) { echo "<span class=\"error_validation\">The Logo has been successfully changed! Refresh the page to see the changed!<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } else { echo "<span class=\"error_validation\">There was an error uploading the logo. Pls. try again.<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } } else { echo "<span class=\"error_validation\">Invalid file format. We are only accepting image file. Pls. try again.<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } } } else { me_redirect_to("edit_logo.php"); } ?> Anyone? thanks hi, I want to download the file, where i have the search query in session variable, in my local system its working good, but in server its not working, any guidance please Code: [Select] <?php include("global.php"); // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } $sql = $_SESSION['emp_search_sql']; // file name for download $filename = "employees_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); header("Pragma: no-cache"); $flag = false; $result = $DB_site->query($sql) or die('Query failed!'); while(false !== ($row = mysql_fetch_assoc($result))) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> Thanks What's the proper way to check if a file exists on a remote server? I know file_exists() works for you local files. I think i need to use something like the following. BUT if the file is not found PHP throws a warning. I know i can put a '@' before fopen() but that just masks the error. Code: [Select] <?php if(fopen("http://www.othersite.com/imageXYZ.jpg", "r")) { echo "File exists."; } else { echo "File does not exist."; } ?> I'm trying to work out if in my form my image field, which currently asks the user to upload from their hard drive, can show the contents of a server folder to select an image or upload a new one. Can this be done?? |