Jump to content

fife

Members
  • Posts

    381
  • Joined

  • Last visited

Everything posted by fife

  1. hi Im trying to make this select drop down echo selected but with no joy. Please help $qGetCounty = "SELECT * FROM Counties ORDER BY FIELD(country,'England','Wales','Scotland'), county "; $rGetCounty = mysql_query($qGetCounty); echo "<select name=\"county\">"; $PrevCountry = ""; while ($county = mysql_fetch_assoc($rGetCounty)) { if ($county['country'] != $PrevCountry) { $PrevCountry = $county['country']; echo "<optgroup label='$PrevCountry'>"; } //MyDetails is the array echo " <option " . ($selected ? "selected=\"selected\"$MyDetails['county']" : "") . " value= '{$county['county']}'>{$county['county']}</option>"; } echo "</select>" ;
  2. ok ive found something but I under understand it I changed my code to if (isset($_POST['Save_photo'])) { $fileName1 = trim($_FILES['new_photo']['name']); $tmpName = $_FILES['new_photo']['tmp_name']; $fileSize = $_FILES['new_photo']['size']; $fileType = $_FILES['new_photo']['type']; $randName = md5(rand() * time()); $fileName = $randName.$fileName1; print $fileSize; exit(); } for testing reasons. If I upload a small file say 270KB it echos 276475 If i then upload a file size 20778KB it echos 0 Can anybody explain this please? Thank you Danny
  3. ok yesterday I posted that none of my error checking was working and that I kept crashing the server. Thanks to some of the posts above two of the error checks works. How ever. The major one that crashed my server yesterday still does not. Im trying to restrict file sizes to only allow below 2MB When I try to upload one the issue is it runs the whole upload (very slow). Then refreshes the page without actually uploading the file. Obvisouly its good the file does not upload but its not good that it tries. It should fail long before the move_upload_file. Here is the code if (isset($_POST['Save_photo'])) { //another photo uploader $fileName1 = trim($_FILES['new_photo']['name']); $tmpName = $_FILES['new_photo']['tmp_name']; $fileSize = $_FILES['new_photo']['size']; $fileType = $_FILES['new_photo']['type']; $randName = md5(rand() * time()); $fileName = $randName.$fileName1; $limit_size = 2097152; $folder = "{$_SERVER['DOCUMENT_ROOT']}members/images/{$row_Club['county']}/"; //now the error check that does not seem to run if ($fileSize >= $limit_size){ print "<div id='clear'></div><p class='formerrors'>Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.</p><div id='clear'>"; exit();} $types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png'); if (in_array($fileType, $types)) { move_uploaded_file($tmpName , $folder.$fileName); } else { $type = "This file does not have a valid extension! Only JPG, PNG, GIF are allowed."; } }
  4. cool thank you ak. Ill be back on in 30 mins to try your changes as my server has crashed. I will post what happens. Again thank you
  5. Ok i have this script that uploads an image. Works good thanks to all you guys out there. There are issues though. I have tried everything but none of the error checking is working. I check for 3 things. 1. file size is less than 2 MB 2. file exists 3. file is a certain type. None of these checkers seems to be working properly. if the image exceeds the file size no error is displayed but the image does not upload. if you try to upload nothing the whole script runs and then crashes my hosts server!!!!!!!!!! (Not good) if you try to upload the none file types allows again it crashes my hosts server!!!!!!!!!!! Basically Im not good enough at php YET to find what my error in the code is as if you upload a correct type and correct size it works. Please please please help! Thank you if (isset($_POST['Save_photo'])) { //another photo uploader $fileName1 = trim($_FILES['new_photo']['name']); $tmpName = $_FILES['new_photo']['tmp_name']; $fileSize = $_FILES['new_photo']['size']; $fileType = $_FILES['new_photo']['type']; $randName = md5(rand() * time()); $fileName = $randName.$fileName1; $limit_size='2097152'; $folder = "{$_SERVER['DOCUMENT_ROOT']}members/images/{$row_Club['county']}/"; if ($fileSize >= $limit_size){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} // } elseif ($fileName1=="") {$error = "Please choose a file to upload"; $success=0;} //elseif ($fileType!== 'image/jpeg' || 'image/gif' || 'image/png' || 'image/JPG') {$error = "false";} $types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png'); if (in_array($fileType, $types)) { // Your file handing script here if(move_uploaded_file($tmpName , $folder.$fileName)) { $Fnew = $fileName; $county = $User['county']; $time = date("h:i A, d/m/Y"); $qInsert = mysql_query("INSERT INTO `images` (`image_name`, `creation_date`, `user`, `county`, club_ID) VALUES ('$Fnew', '$time', '".$User['memberDID']."', '$county', '".$row_Club['clubID']."')") or die (mysql_error()); $image = mysql_insert_id(); $url = "New-photo-details.php?image=$image"; header("Location: $url"); } } else { $message = "This file does not have a valid extension! Only JPG, PNG, GIF are allowed."; $success = 0; } }
  6. xyph Are you saying that it doesnt matter what they upload as long as it cant be ran? doe that mean checking the file types is pointless? this is still my first image uploader and the error checking part is proving difficult!
  7. Ok. I have made a very simple image uploader but I have major cross browser issues that I didnt think were possible. I thought php was the same across all browsers but obviously not. Here is the issue. I have an error checker that if the image is not of a certain type it simply says "nope" If I upload an image in google crome or IE 9 then the image uploads no problem to the server and a ref to the database. If I use the more popular browsers like IE7 or IE 8 my error of "nope" comes back and no script is executed. code first the form <form action="" method="post" name="select_photo" enctype="multipart/form-data"> <input type="file" name="new_photo" id="new_photo"> <input name="Save_photo" type="submit" value="Submit" alt="Upload this photo"> </form> then the script if (isset($_POST['Save_photo'])) { //another photo uploader $fileName1 = $_FILES['new_photo']['name']; $tmpName = $_FILES['new_photo']['tmp_name']; $fileSize = $_FILES['new_photo']['size']; $fileType = $_FILES['new_photo']['type']; $randName = md5(rand() * time()); $fileName = $randName.$fileName1; $folder = "{$_SERVER['DOCUMENT_ROOT']}members/images/{$User['county']}/"; if ($fileSize >2097152){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} // } elseif ($fileName1=="") {$error = "Please choose a file to upload"; $success=0;} $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($fileType, $types)) { // Your file handing script here if(move_uploaded_file($tmpName , $folder.$fileName)) { $Fnew = $fileName; $county = $User['county']; $time = date("h:i A, d/m/Y"); $qInsert = mysql_query("INSERT INTO `images` (`image_name`, `creation_date`, `mem`, `county`) VALUES ('$Fnew', '$time', '".$User['member_id']."', '$county')") or die (mysql_error()); $url = "New-photo.php?image=$Fnew"; header("Location: $url"); } } else { $message = "nope"; } } I think it has something to do with the in_array function but. I have tried isset and array_key_exists but neither of them work properly!
  8. EdwinPaul sorry I dont understand. this is my first working image uploader. Where would I put the error result?
  9. Im trying to make sure that a user can not click upload without first choosing an image to upload. for some reason now I have put the error checking into my file uploader it has stopped working completely. It just keeps flashing the "$msg" variable. Here is the code...... if (isset($_POST['Save_photo_x'])) { $fileName1 = $_FILES['new_photo']['name']; $tmpName = $_FILES['new_photo']['tmp_name']; $fileSize = $_FILES['new_photo']['size']; $fileType = $_FILES['new_photo']['type']; $randName = md5(rand() * time()); $fileName = $randName.$fileName1; $folder = "{$_SERVER['DOCUMENT_ROOT']}members/images/{$User['county']}/"; if ($fileSize >2097152){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} elseif (!($fileType =="image/jpg" OR $fileType=="image/gif" OR $fileType=="image/png")){$msg="You must select a file to upload and your uploaded file must be of JPG/GIF/PNG. Other file types are not allowed<BR>"; $success=0; } else {$success=1;} if ($success==1) { $var = move_uploaded_file($tmpName , $folder.$fileName); } } any help would be appreciated.
  10. Ok thats great thank you. I have changed that but the page is still not updating with the new business details. After that form has processed i am left with a new $_SESSION variable (which is basically an ID) then I have this code $Thebus = TheBus($_SESSION['busID']); echo $Thebus['name']; and the function function TheBus($busID) { $Thebusq = mysql_query("SELECT * FROM business WHERE busID = '$busID'"); $Thebus = mysql_fetch_array($Thebusq); return $Thebus; }
  11. Im having issues destroying a session and then re-creating the session again. Its easier to show the code. First of all I have a form that shows you different business details. <form action="" method="POST" id="mybusfrm"> <ul id="bus_list"> <li><input type="image" src="<?php if ($CP['logo']=='logo_default.jpg') { echo "/images/logo_default.jpg"; } else { echo "/members/images/{$CP['county']}/{$CP['logo']}"; } ?>" width="60" height="60" id="businsert" name="businsert" /> </li> <li><?php echo $CP['name']; ?></li> <input name="bus" type="hidden" value="<?php echo $CP['busID'];?>"> <input name="pap" type="hidden" value="<?php echo $CP['permission'];?>"> </ul> </form> I have two hidden fields with the business ID and the users permission. The information that displays on the page is taken from the session $_SESSION['busID'] This session is fed through a function that gets the details. Before that obviously if the user clicks a different business then the page needs to update with the business details from the newly replaced session variable. so for the code that changes the variable name. if(isset($_POST['businsert_x'])){ session_destroy($_SESSION['busID']); session_destroy($_SESSION['pap']); $bus = trim($_POST['bus']); $pap = trim($_POST['pap']); if (is_numeric($bus) && is_numeric($pap)) { $bus = mysql_real_escape_string($bus); $pap = mysql_real_escape_string($pap); $_SESSION['busID'] = $bus; $_SESSION['pap'] = $pap; $url = "index.php"; header("Location: $url"); } else {echo "Fail";}} //end check club This code has been previously working but for some reason its now stopped. Also I get a logo error of Wrong parameter count for session_destroy() in /home/sites/site.com/public_html/members/index.php on line 10, referer: http://www.site.com/members/index.php there is also one for line 11. These two lines are the session_destroy($_SESSION['busID']); lines respectively. I have tried adding to the page refresh...... $url = "index.php/business='$busID'&'$pap'"; To see if the variables are even changing when a different business is selected and they do. Please help. Thanx
  12. is it possible the file name is wrong. it looks as follows 0000000003253a8ba618e5490569e878696d3b20f1.image/jpeg'
  13. yes I know what the root mean. My site is hosted from Heart Internet. A massive company in which My words would have no effect over. If im in the folder /members/edit and my page is called edit. Then surely to reference an image from the root it would be /images or even ../images Other images and files on the site are used this way so why when I write $folder = "/members/images/{$intro['county']}/"; does it say the path does not exist and why even if i type it not go from. http://www.thesite.com/members/images/ (image name here) does it still give me a server error like so.............. [Thu Jun 23 18:49:04 2011] [error] [client 94.5.254.197] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpWwYpSt' to 'http://www.site.com/members/images/Lancashire/0000000003d75b6a81a8c42da6028c835dd7cda019.image/jpeg' in /home/sites/site.com/public_html/members/edit/edit-club-intro.php on line 35, referer: http://www.site.com/members/edit/edit-club-intro.php Maybe I dont understand properly as im really confused now. Can somebody at least explain the previous post or the error above? Thank you
  14. if you put /members then the path looks perfect on the error that it generates
  15. cool thanks again but if I put $_SERVER["DOCUMENT_ROOT"] at the front of the string $folder = "".$_SERVER["DOCUMENT_ROOT"]."members/images/{$intro['county']}/"; it error again but the path looks as follows........... http://www.site.com/public_html/members/images/lancashire/000000000324587b2446acd77b5a31fca2e7fec2fc.image/jpeg Obviously public shoud not be there
  16. right I noticed it had the file type on it twice so I changed the move upload file code to move_uploaded_file($tmpName , "$folder".$FileName) or die(mysql_error()); Im still getting the error that says the directory does not exist. Which is not true. The directory that it is referring to does exist on the server.
  17. ive tried put in ../../ to send the $folder back to the root but same error
  18. Ok thank you PFMaBiSmAd but I now have this error. This is my first image uploader so I have no idea how to trouble shoot it. ive pinched and wrote my own code. The uploady part was from a tut so I cant see whats up with it Warning: move_uploaded_file(/members/images/Lancashire/000000000354ca08848008b86f5057364ae0dc09b8.image/jpegimage/jpeg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/sites/site.com/public_html/members/edit/edit.php on line 37 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpTFdk4s' to '/members/images/Lancashire/000000000354ca08848008b86f5057364ae0dc09b8.image/jpegimage/jpeg' in /home/sites/site.com/public_html/members/edit/edit.php on line 37 line 37 is move_uploaded_file($tmpName , "$folder".$FileName.$fileType) or die(mysql_error());
  19. I get this....... edit_vsvb0n90nx.php on line 14 but that refers to a query that I know works fine as was already on the page. I dont understand the _vsvb0n90nx.php as the page is just called edit.php with nothing after it
  20. if you mean for the image no. Its just a varchac of length 200 for now. Its not getting that far though as the image is not appearing on the server either.
  21. Im trying to just simply upload an image and the insert it into my database. I have my code which I have stripped all error checking out. When it runs the page refreshs but the file does not appear in the folder and the table is not updating. There are no server log errors or anything can someone help please... This will be an update form eventually but for now Im just trying to insert the image if (isset($_POST['update_field'])) { // // $intro = trim($_POST['intro']); // $intro = mysql_real_escape_string($intro); // $intro = mysql_query("UPDATE clubsstuff SET intro = '$intro' WHERE ID = '".$intro['cID']."' ") or die(mysql_error()); //another photo uploader $fileName = $_FILES['intro_image']['name']; $tmpName = $_FILES['intro_image']['tmp_name']; $fileSize = $_FILES['intro_image']['size']; $fileType = $_FILES['intro_image']['type']; $randName =$User['memberID'].md5(rand() * time()); $FileName = $randName; $folder = "/members/images/{$intro['county']}/"; //if ($FileSize >250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; //$file_upload="false";} // // } // // if (!($FileType =="image/jpeg" OR $intro_image_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>"; //$file_upload="false";} move_uploaded_file($tmpName , "$folder".$FileName.$fileType) or die(mysql_error()); //connect to database again include('../../Connections/database.php'); $FileName; $time = time(); $qInsert = "INSERT INTO `images` (`image_name`, `creationDate`, user,c ID, album_id, intro_image) VALUES ('$FileName', '$time', '".$User['member_ID']."', '".$intro['cID']."', '1', 'yes')"; $rInsert = mysql_query($qInsert) or die(mysql_error()); //Tells you if its all ok $url = "edit.php"; header("Location: ".$url.""); and the form <form action="" method="POST" enctype="multipart/form-data" name="c_image"> <input type="file" name="intro_image" id="intro_image"> <input type="submit" name="update-field" id="update-field" value="Update">
  22. Hi. I have just a question. Lets say you are looking for a band on the web. You type "Skyline Ablaze" The first thing back you are going to find in myspace.com/skylineablaze My question is this. How do they create a URL like that? Obviousness each person using the site does not have their own folder. Im guessing its a htc file. Because I have no idea what this is called I cant find any info on google. I was just wondering if anybody else has come across this before. Thank you
  23. solved. It was what you said. I was reading the page without the real escape, nl2br and addslashes functions. Thank you both for the error checking code. i will be sure to use that again in the future!
  24. cool guys one moment
  25. yes sorry pikachu2000 its here. That from from a copy page if(isset($_POST['insert_club'])){ //Process data for validation $intro = nl2br((trim($_POST['intro']))); $about = trim($_POST['about']); //perform validations $errors = array(); if(empty($intro)) { $errors[] = "Please enter an introduction to your company"; } if(empty($about)) { $errors[] = "Please enter an about section of your company"; } //Check if there were errors if(count($errors)===0) { $intro = mysql_real_escape_string($intro); $about = mysql_real_escape_string($about); // Prepare data for db insertion $query = "UPDATE `table` SET `intro` = '$intro', `about` = '$about' WHERE validationID = '$validation1'"; $result= mysql_query($query) or die(mysql_error());
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.