PHP - Listing Only A Certain Type Of File In Php?
Hi.
I want to create a list of files in a directory. But I don't want all the files to be listed, only .gif, .jpg and .bmp. Does anyone know the PHP code how to do that? (My directory name is 'images' if you need that). Thanks! Similar TutorialsHey, I dont know whats wrong but i was hoping someone could take a look at the code and provide some errors that maybe causing this script not to work. I want it to display all the .jpg pictures in thumbnails, it currently does not even get the pictures. code: <?php $pic_listing = mysql_query("SELECT * FROM toplist WHERE id='". $id ."'") or die(mysql_error()); while($serverpic = mysql_fetch_array($pic_listing)) { $servername = $serverpic["servername"]; } $directory = "images/serverpic/" . $servername . ""; $images = glob("" . $directory . "*.jpg"); if(empty($images)) { ?> <div class="highslide-gallery"> <?php foreach($images as $image) { ?> <a href="images/serverpic/<?php echo $servername . "/" . $image; ?>" class="highslide" onclick="return hs.expand(this)"> <img src="images/serverpic/<?php echo $servername . "/" . $image; ?>" alt="Highslide JS" width="100" height="100" title="Click to enlarge" /> </a> <div class="highslide-caption"> <?php } ?> </div> </div> <?php } ?> ok I have a text file that has ids listed each on a new line how can I go about assigning each id to a variable so like 12312412 23432443 34654366 56456345 the variable $ids = all of the ids above one at a time in an array so like $ids[] = 12312412; $ids[] = 23432443; $ids[] = 34654366; $ids[] = 56456345; Hi All,
I want to include my terms and conditions in an ebay listing.
The reason for this is to ease the process if and when i need to change the terms.
I stopped using eBay about a year ago and back then is used this code to display my terms withing the eBay lisitng.
<?php include ('http://www.example.com/terms.php'); ?>
NOw when i put that code into the listing it doesnt display.
I tested this out on my own server and it didnt display there either so I now it isnt eBay.
I also tried emoving the brackets without success.
The only way I can get it to display as include on my server is to use a relative path, which isnt the result I need
Has something changed in the past year?
Is there another way to display an external file using an absolute path to an external file?
Many Thanks
Hiya, Firstly, I'm a complete novice, apologies! But I have got my upload.php working which is nice. I will post the code below. However, I would now like to restrict the file size and file type to only word documents. I currently have a restriction of 200KB but it's not working - no idea why as I've looked at other similar codes and they look the same. Also, just to complicate things - can I stop files overwriting each other when uploaded? At the moment, if 2 people upload files with the same name one will overwrite the other. Is this too many questions in 1? Any help is very much appreciated! Code below: Code: [Select] <form enctype="multipart/form-data" action="careers.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 200) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "Your file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded."; } else { echo "Sorry, there was a problem uploading your file."; } } ?> Folks,
I am building a membership script for 21 months now!!! That long!!!
Not pasting the whole script as really long. Would do your head in. if($_SERVER["REQUEST_METHOD"] == "POST") { if(!isset($_FILES["id_verification_video_file"])) //REtype { echo "no isset"; } else { $id_verification_video_file = $_FILES['id_verification_video_file']; //REtype //Feed Id Video Verification File Upload Directory Path. $directory_path = "uploads/videos/id_verifications/"; //Make Directory under $user in 'uploads/videos/id_verifications' Folder. if(!is_dir("$directory_path" . "$user")) { $mode = "0777"; mkdir("$directory_path" . "$user", "$mode", TRUE); //Thanks Requinix for my "$mode" typo hint. } //Grab Uploading File details. $Errors = Array(); //SHOULD I KEEP THIS LINE OR NOT ? $file_name = $_FILES["id_verification_video_file"]["name"]; $file_tmp = $_FILES["id_verification_video_file"]["tmp_name"]; $file_type = $_FILES["id_verification_video_file"]["type"]; $file_size = $_FILES["id_verification_video_file"]["size"]; $file_error = $_FILES['id_verification_video_file']['error']; //Grab File Extension details. $file_extension = pathinfo($file_name, PATHINFO_EXTENSION); if(file_exists('$directory_path' . '$user/' . '$file_name')) { $Errors[] = "Error: You have already uploaded a video file to verify your ID!"; exit(); } else { //Feed allowed File Extension(s). $allowed_file_extensions = array("mp4" => "video/mp4","wmv" => "video/wmv"); //Feed allowed file size. $max_file_size_allowed_in_bytes = 1024*1024*100; //Allowed limit: 100MB. $max_file_size_allowed_in_kilobytes = 1024*100; $max_file_size_allowed_in_megabytes = 100; $max_file_size_allowed = "$max_file_size_allowed_in_bytes"; //RETYPE //Verify File Extension. if(!array_key_exists($file_extension,$allowed_file_extensions)) die("Error: Select a valid video file format. Select an MP4 or WAV file."); //Verify MIME Type of the file. elseif(!in_array($file_type,$allowed_file_extensions)) { echo "Error:<font size ='5' font color ='red'><b>There was a problem uploading your video file $file_name! Make sure your file is an MP4 or a WAV file. You may try again now.</b></color></size>"; //THANKS TO REQUINIX FOR BRINNGING IT TO MY ATTENTION I AM STILL PROCESSING THE SCRIPT AFTER THIS LINE WHEN I SHOULD NOT. exit(); } //Verify File Size. Allowed Max Limit: 100MB. elseif($file_size>$max_file_size_allowed) die("Error: Your Video File Size is larger than the allowed limit of: $max_file_size_allowed_in_megabytes."); //Fixed variable name typo. Thanks to Requinix & Simon JM. //Move uploaded File to newly created directory on the server. move_uploaded_file("file_tmp","$directory_path" . "$user/" . "$file_name"); //Notify user their File was uploaded successfully. echo "<font size ='5' font color ='red'><b>Your Video File \"$file_name\" has been uploaded successfully! You will get notified once your Id has been verified successfully.</b></color></size>";
Can you spot my coding error ? I have this code which uploads fine but I am trying to limit the type of files users can upload. For some reason this code still let any file type to be uploaded being very new to php any help would be Appreciated. Quote Code: [Select] <?php if ((($_FILES["image"]["type"] == "image/gif") || ($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/pjpeg")) && ($_FILES["image"]["size"] < 20000)) { if ($_FILES["image"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["image"]["name"] . "<br />"; echo "Type: " . $_FILES["image"]["type"] . "<br />"; echo "Size: " . ($_FILES["image"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["image"]["tmp_name"]; } } $target = "testimages/"; $target = $target . basename( $_FILES['image']['name']); // $company=$_POST['company']; $image=($_FILES['image']['name']); mysql_connect("localhost", "user", "pass") or die(mysql_error()) ; mysql_select_db("testupload") or die(mysql_error()) ; mysql_query("INSERT INTO `table` (company, image) VALUES ('$company', '$image')") ; if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { echo "Sorry, there was a problem uploading your file."; } ?> I have created a table called directories. Now basically I have two fields; dirID (INT) directory (VARCHAR) now I am fully aware this might sound like more of an SQL question but I have three physical directories: db/images/web1 db/images/web2 db/images/web3 I have inputted them into the database but I was just wondering, how could I created a page which links those records to a directory. I want to have each row hyperlinked, with the output page displaying list of contents for each directory. How can I possibly achieve this please? How to attach any file type to an email using php mail() It should attach any file that you select. What would be the Content-type: value? Thanks! I have a Windows-style ini file that contains entries as such:
[Timers] Timer(1)=50 Timer(2)=30 Timer(3)=20 The entries represent an array of 3 different timers Apparently parse_ini_file can't deal with the () format. Is there any way to use this format ini file without having to change how arrays are designated? Hey guys! I'm making a locally run web based application for entering/storing/editing data. I am trying to do this thing where I export a 'records.txt' file to a different location which can be selected by the user. I have a lame <input type='text' value='H:\'> box going on which I was going to use to define the path for the file to be saved, but I want to be able to use a pop up windows (or whatever native OS finder application) just like the one which appears when you use <input type='file'>. Now that I think about it, I think this is more of a html question, but it's 2.30am and my project is due today... See! what the hell, I just habitually pressed ctrl-s after working in dreamweaver for hours and the exact function which I am looking for popped up, how do I do that?! Please thanks guys Hello, Iv written a small script in JS to add input boxes of the type file to the page.. My problem is when i use multiple of those input boxes and submit the form the $_FILES variable only reads 1 of those boxes.. This is the javascript im using: Code: [Select] function addImageBox() { var imageBoxes = document.getElementById("imageBoxes"); var tr = document.createElement("tr"); var td = document.createElement("td"); var td2 = document.createElement("td"); var inputFile = document.createElement("input"); inputFile.setAttribute("type", "file"); inputFile.setAttribute("name", "image[]"); inputFile.setAttribute("style", "width: 450px"); td.appendChild(document.createTextNode("Image")); td2.appendChild(inputFile); tr.appendChild(td); tr.appendChild(td2); imageBoxes.appendChild(tr); } When i add 2 boxes (making it 3 boxes on the page in total) and count the $_FILES var after submiting the form, the count method returns 1, and when i var_dump it only 1 array is in $_FILES. Any idea's? thanks! hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! directory listing: hi guys, im using a PHP script to output a list of documents in different directory's using a single index.php (apart from the style obv), its not a major issue but bugging me as to how to get it to ignore the "up" link for directory navigation. its outputting the below: . .. this is annoying me... is it possible to get it to ignore these and not output them? Code: [Select] <link rel="stylesheet" type="text/css" href="style.css"> <span class="note"> <?php echo "directoryname3"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname3</B>"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname3</B>"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname</B>"; ?></span> <?php $dir="directoryname"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> Hey guys I have found this peice of code and messed around with it. I got it to work with Thickbox and I would like to know how to seperate my images aka files to every 4th column. Heres the code I found and tweaked. The images would look great if it was every 4th column they break. Also where would I place he echo command if I want it to display information about that image. Heres the code... Code: [Select] <? /** * Change the path to your folder. * * This must be the full path from the root of your * web space. If you're not sure what it is, ask your host. * * Name this file index.php and place in the directory. */ // Define the full path to your folder from root $path = "images/default/"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "default.php" ) continue; echo "<a href=\"images/default/$file\" class=\"thickbox\"><img src=\"images/default/$file\" height=\"150\" width=\"150\" border=\"0\"></a>"; } // Close closedir($dir_handle); ?> I have a mysql database set up with 4 fields - id, month, day, event. The database will be filled with something like: month=Jan, day=4 and event=Meeting. All are text fields. The display will be Jan. 4: Meeting I can set up the PHP to display the database in a unordered list. The code for this is: <?php $result = @mysql_query("SELECT id, month, day, event FROM homecalendar"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { echo '<li>' . $row['month'] . $row['day'] .': ' . $row['event'] . '</li>' ; } ?> How can I limit the code to display items for only the current month and the next month? Ok so I don't even know where to start with this idea so I thought I would poke around here for some inspiration. On my server I have a Directory. In that directory I have roughly 300 folders with 5,000 files + 1 index.php (so 5,001 files but I want to ignore the index.php in the listings) per directory. Anyway what I am trying to do is list all the files and load them into a database. What my ideal goal would be is device a script that I would put in the root directory with the 300 or so subdirectories and let it run through the directories automatically one by one, listing all the files in them and then storing them in the database. I'd break it down more but that part I can figure out on my own cause I do want to do more than just store the file names and corresponding directory its in in the DB. My issue is I can find anything or figure anything out that will cycle through all directories, thats what I need to figure out first. Hi friends, i want to ask a question. i have two page: "slider.php" and "mansethaberler.php" i extract two data from the database, named "addnews_headline" and "addnews_image" in slider.php. i create link to extracted "headline" from the database. See i added first image. when i clicked the link, link is heading to the second page "mansethaberler.php" and in "mansethaberler.php" with "SELECT" i extract from database "headline" and "image". Now i want to do that. When i clicked the link in "slider.php" i want to listing the image and headline in "mansethaberler.php". "mansethaberler.php" <?php $veri = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id",PDO::FETCH_ASSOC)->fetchAll(); ?> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <?php foreach ($veri as $haber) { ?> <div style="border:1px solid black; height:50px; background-color:#17a2b8; color:white; line-height:50px; text-align:center;"><?php echo $haber["habereklesayfasi_baslik"]; ?></div> <div class="row no-gutters"> <img class="col-lg-12 mt-2" src="upload/images/<?php echo $haber["haberekle_resim"]; ?>" style="max-height:444px;"> </div> </div> <div class="col-lg-12 ml-auto mt-1 mb-1" style="padding-left:7px;"><?php echo $haber["haberekle_konu"]; } ?></div> "slider.php" <img src="upload/images/<?php echo $row["haberekle_resim"]; ?>" width="832" height="502"> <!-- upload/images/ ile <?php ?> tag'leri arasında boşluk olursa link kırılıyor. Resim çıkmıyor. --> <div class="carousel-caption"> <p><a href="mansethaberler.php"><?php echo $row['haberekle_baslik']; ?></a></p> </div>
Edited August 19, 2020 by CodingStudent i forgot to put the most important codes |