PHP - How To Add A Default File?
I have this code, for an Upload Form, that works successfully renaming and moving an uploaded file to the upload/ folder.
Similar Tutorialsok this grabs mp3 from 4shared but the download link appears as preview.mp3 how could i get it to be renamed as the original reach name like here_without_you.p3 or something else? Code: [Select] <?php $file = file_get_contents("http://www.4shared.com/audio/PmMMpPFs/here_without_you.htm"); $body = preg_replace("/.*file[^=]*=|\&volume.*/si", "", $file); preg_match("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\-\:\=\;\.\@\/]+)))/is",$body, $result); $download_url = $result[1]; print_r($download_url); ?> My 1st try practice uploading file to the server and it was successful. Now I wonder how can I set a default file name to the file that will be uploaded and overwrite the existing one. I have tried experimenting on the code but I can't get it to work. Here's my simple code.. edit_logo.php Code: [Select] <?php <form enctype="multipart/form-data" method="post" action="uploaded_logo.php"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <tr> <td>Choose a Logo to Upload: </td> <td><input name="uploaded_file" type="file" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="Upload File" name="submit>"</td> </tr> </form> ?> uploaded_logo.php Code: [Select] <?php if($_FILES['uploaded_file']["type"] == "image/gif") { $target_path = "logo/"; $target_path = $target_path. basename($_FILES['uploaded_file']['name']); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) { echo "<span class=\"error_validation\">The Logo has been successfully 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>"; } ?> So what the code suppose to do is.. If I upload an image file as the new logo it should have the default logo name "my_logo.gif", then it will overwrite the existing one... Anyone? hello and good day dear Linux-experts, i want to install a new opensuse linux on a notebook. i want to upgrade is the following: this one: Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320, 2,10 GHz, 4 GB 320 GB hdd-drive what is wanted: i want to do a total fresh installation i want to have not tooo much partitions! i only want to run opensuse 13.2 i want to have some kind of native linux partitions - such as ext 4 - # what do you suggest - should go with the new default BTRFS file system?!? well to begin with the beginning: i applied the following commands a. lsblk b. fdisk -l see the results,,,, ; linux-c5sz:/home/martin # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465,8G 0 disk ├─sda1 8:1 0 4G 0 part [SWAP] ├─sda2 8:2 0 102M 0 part ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 2G 0 part ├─sda6 8:6 0 4G 0 part ├─sda7 8:7 0 10G 0 part ├─sda8 8:8 0 20G 0 part / └─sda9 8:9 0 389,6G 0 part /home sr0 11:0 1 1024M 0 rom and the following fdisk -l linux-c5sz:/home/martin # fdisk -l Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors Units = Sektoren of 1 * 512 = 512 byte Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xb8fa3ecd Gerät boot. Anfang Ende Blöcke Id System /dev/sda1 63 8385929 4192933+ 82 Linux swap / Solaris /dev/sda2 8385930 8594774 104422+ 83 Linux /dev/sda4 * 8803620 976768064 483982222+ 5 Extended /dev/sda5 8803683 12996584 2096451 83 Linux /dev/sda6 12996648 21382514 4192933+ 83 Linux /dev/sda7 21382578 42347339 10482381 83 Linux /dev/sda8 117821440 159766527 20972544 83 Linux /dev/sda9 159768576 976766975 408499200 83 Linux linux-c5sz:/home/martin # subsequently the questions; which partition logic should i choose. what is wanted: i want to have not tooo much partitions! i only want to run opensuse 13.2 note: i want to erase all the existing partition logic /(that is currently existing) i do this with Gparted. which partitions should i take? which file system ? i am curious to get to know your ideas I am loading a link with ajax. When the link pops on the screen and I click it, I get redirected to my 404 page and my lightbox doesn't load. If the link pops in and I refresh my browser, then I click the link my lightbox will show up. How can I do a prevent default on the <a href> in pure JS? No frameworks please. I have a few dropdown forums and would like it to select the current values that are requested. Code: [Select] global $filename,$fileid,$filetype,$filedir,$fileby; global $months,$pg; echo "<h2>Search Files</h2>"; echo "<p>"; echo "<form name = 'File_Search' action = '#' method = 'POST'>"; echo "<table border=\"0\" width=\"100%\"><tr>"; echo "<td>File Name<br><input type = 'text' name = 'name'></td><td>File Type<br><select name = 'type'> <option value = '0'>All Types</option> <option value = 'o'>Official Files</option> <option value = '1'>Quests</option> <option value = '2'>Graphic/Spritesheets</option> <option value = '3'>Entity/Scripts</option> <option value = '4'>Sound/Music</option> <option value = '5'>QuestPack/Programs</option> <option value = '6'>Miscellaneous</option> </select></td>"; echo "<td>Order By<br><select name = 'order'> <option value = '0'>Last Updated</option> <option value = '1'>ID</option> <option value = '2'>Name</option> <option value = '3'>Downloads</option> <option value = '4'>Rating</option> <option value = '5'>Points</option> <option value = '6'>Random</option> </select></td>"; echo "<td>Acending?<br><select name = 'dir'><option value = '0'>False</option><option selected value = '1'>True</option></select></td>"; echo "</tr><tr><td rowspan = '4'><input type = 'submit' name = 'search' value = 'search'></td></tr></table></form>"; echo "</p>"; So if the $filetype equals 2 I want the dropdown box to show "Graphic/Spritesheets" by default. BTW Official Files is not actually a type so that's why I chose to give it a small letter o and will work the same way as All Types but run a different function. $fileby is used for the OrderBy field. $filedir is for the Acending field. The other data is for the other parts of the script. If you like you can give advice on the name's default because you may have a better method then what I have in my head. Hi guys and gals , got a minor problem. I have a table in which i want the "photo" column to have a default value of "noimage.jpg". I set the default value to "noimage.jpg" and put "as defined" too. but when i fill the form in and leave the upload field blank it doesnt show the noimage.jpg as it should and in the mysql table it leaves it blank and not with default value. Here is the inserts.php which adds the data to the mysql table. Can you help please. <CENTER><B>Vehicle Added</B></CENTER> <BR> <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); $CarName = mysql_real_escape_string(trim($_POST['CarName'])); $CarTitle = mysql_real_escape_string(trim($_POST['CarTitle'])); $CarPrice = mysql_real_escape_string(trim($_POST['CarPrice'])); $CarMiles = mysql_real_escape_string(trim($_POST['CarMiles'])); $CarDescription = mysql_real_escape_string(trim($_POST['CarDescription'])); $pic = mysql_real_escape_string(trim($_FILES['uploadedfile']['name'])); $target_path = "images/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; echo "<br />"; } else{ echo "There was an error uploading the file, please try again!"; } mysql_query("INSERT INTO cars (CarName, CarTitle, CarPrice, CarMiles, CarDescription, photo) VALUES('$CarName', '$CarTitle', '$CarPrice', '$CarMiles', '$CarDescription', '$pic' ) ") or die(mysql_error()); echo "The vehicle data has been added!"; ?> I am using this php code <?php echo $_GET['CiFrame']; ?> to check the url for the variable CiFrame, this allows me to link to a page through my page containing the iframe. Here is my iframe code. <iframe name="CiFrame" width="727" height="805" src="<?php echo $_GET['CiFrame']; ?>" scrolling="auto" frameborder="0"></iframe> The problem is that if the url does not contain a variable the iframe will not open a page. How can i set a default variable if one is not provided? Thank You How to define default folder. For example I have folder images and in that folder specific image. In the root directory I have index.php with Code: [Select] <?php require_once("public/includes/header.php"); ?>and in index.php there are links which goes to different folder: Code: [Select] <a href="public/sajt/kategorija.php?id=<?php echo $id; ?>">which also have header.php, but there is no image. How to make default folder for image, or some similar solution? In a Switch statement, can you give the Default: a specific name, maybe like this... switch ($resultsCode){ // Missing Primary Key. case 'COMMENT_MISSING_KEYS_2050': echo '<h1>System Error</h1>'; echo '<p>A Fatal Error has occurred. Please contact the System Administrator. (2050)</p>'; break; default 'DEFAULT_CATCHALL_ERROR_CODE_9999': echo '<p>You have reached the catch-all error code... (9999)</p>'; break; Debbie How do I set the date format so that it's always going by the UTC date? I've used: Code: [Select] date_default_timezone_set('UTC'); but, when I change my date on my computer, the date changes on the website. This is really confusing me, googled different ways for like 10/20 minutes and can't find anything. If anyone can help it'd be great, Thanks, Andy. Hi, I am trying to get the date and time that a particular table was last updated, which the code below does, but it doesn't seem to be putting it in the correct timezone, it is 5 hours behind, anyone know why this is? or how i can fix it? Thanks Code: [Select] <?php date_default_timezone_set('Europe/London'); $query = "SELECT UPDATE_TIME FROM information_schema.tables WHERE TABLE_SCHEMA = 'tffdb' AND TABLE_NAME = 'test_team_points'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo $row['UPDATE_TIME']; ?> Hi. I have drop down boxes for date and time that work. The year is a problem because I am using variables instead of fixed values. Code: [Select] <select name="Year" style="width:60px"> <option value="2010" >Test <option value="<?=$ThisYear?>" <? if ($Year == "<?=$ThisYear?>"){?> SELECTED <?}?> ><?=$ThisYear?> <option value="<?=$NextYear?>" <? if ($Year == "<?=$NextYear?>"){?> SELECTED <?}?> ><?=$NextYear?> </select> <select name="Hour" style="width:50px"> <option value="10" <? if ($_SESSION["Hour"] == "10"){?> SELECTED <?}?> >10 <option value="11" <? if ($_SESSION["Hour"] == "11"){?> SELECTED <?}?> >11 <option value="12" <? if ($_SESSION["Hour"] == "12"){?> SELECTED <?}?> >12 <option value="13" <? if ($_SESSION["Hour"] == "13"){?> SELECTED <?}?> >13 <option value="14" <? if ($_SESSION["Hour"] == "14"){?> SELECTED <?}?> >14 <option value="15" <? if ($_SESSION["Hour"] == "15"){?> SELECTED <?}?> >15 <option value="16" <? if ($_SESSION["Hour"] == "16"){?> SELECTED <?}?> >16 <option value="17" <? if ($_SESSION["Hour"] == "17"){?> SELECTED <?}?> >17 <option value="18" <? if ($_SESSION["Hour"] == "18"){?> SELECTED <?}?> >18 <option value="19" <? if ($_SESSION["Hour"] == "19"){?> SELECTED <?}?> >19 <option value="20" <? if ($_SESSION["Hour"] == "20"){?> SELECTED <?}?> >20 </select> however this works Code: [Select] <select name="Year" style="width:60px"> <option value="2010" >Test <option value="<?=$ThisYear?>" <? if ($Year == "2011"){?> SELECTED <?}?> ><?=$ThisYear?> <option value="<?=$NextYear?>" <? if ($Year == "2012"){?> SELECTED <?}?> ><?=$NextYear?> </select> Can anyone help with this please TIA Desmond. Hello, i know this is a very silly question but it bothers me to know the reasoning behind it. My application has a design where the functions are stored in functions.php and variables are stored in variables.php. There are some functions that have variables that i might change often and the reason i don't directly use them in the argument itself is so that in future if i have to change the default argument's value , then i wouldn't have to scroll through all the functions and look for it. I have a slippery memory i know i will be able to remember it better if i store custom global variables separately and custom global functions separately. I tried searching these forums for this but its giving me a message like "search daemon not found" or something like that.. Anyways , coming to the point, i know that PHP doesn't accept variables as default arguments but may i know the reasoning behind this? If i understand the reasoning behind this i know it will stick better in my head.So..why does a function not allow a variable as a default value? Or if anyone has a link to explaining this behaviour in PHP, i would appreciate it if you could pass it on! Thank you This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=356851.0 Hi I have been trying to get a value to be selected in a mysql populated dropdown list but can't get it to work and was hoping someone could help I have a database with user info in it and this is an update page where they can update their details. The code i have (which doesn't work) is: <select name="agency"> <? $query1 = mysql_query("SELECT * FROM agents ORDER BY agent ASC",$connect); while($myrow = mysql_fetch_assoc($query1)){ $agent = $myrow['agent']; echo "<option"; if ($agent == $agency) { echo "selected='selected'"; } echo ">$agent</option>"; } ?> </select> The $agency value is the current agency which is stored in the users profile and the value does exist in the list which is being populated (also, i have define $agency further up in my code) so i don't know why the selected value won't display. No value is displayed in the dropdown list on the page - but the values are in the list if i remove the selected='selected' part of the code. Any help yould be greatly appreciated. Merry Christmas Andy Ok, i can't understand whats wrong with the DATE field in MySQL and PHP. I have a form in PHP witch has 3 birth day dropdown menus that looks like this (YYYY-MM-DD). An in my database i have a birth_day colum with DATE as type and i've tried to set the default value to "None" and "0000-00-00" but nothing works. Everytime i try to input something (e.g. 1993-16-05) i get this error: Incorrect date value: '05' for column 'birth_day' at row 1 I've tried to set the value for the "Day" dropdown in the PHP form to both 5 and 05 but still nothing, what am i doing wrong? having a problem figuring out how to change the default on a drop down box to equal the users current timezone. So when they view it the drop box default is showing what their setting is atm. The problem is the value is differant from whats displayed. Is it possible to some how say if users time offset is equal to a option value set selected=""> to yes. if not what is the idea behind this? Cant find a guide showing an example In other drop down boxes where the value is the same as whats displayed I just simply created another value field at the top of the list and echo it in. Code: [Select] <select name="gmt"> <option value="-28800">(GMT -0800) Pacific Time </option> <option value="-25200">(GMT -0700) Mountain Time </option> <option value="-21600">(GMT -0600) Central Time</option> <option value="-18000">(GMT -0500) Eastern Time </option> </select> This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=333290.0 In PHP when you post a form the default font is Times New Roman how do I changes the font to arial Hi all, I have this script below where I am trying to display a default image if an image can not be found. For some reason though it is not working. <?php foreach (glob('./aircraft/' . $rowX['reg'] . '[0-8].jpg') as $file) { if (file_exists($file)) { echo "<img src=\"" . $file . "\" /><br />"; } else { echo "><img src=\"aircraft/wrightflyer.jpg\" /><br />";} } ?> |