Jump to content

kurt.santo

Members
  • Content Count

    925
  • Joined

  • Last visited

Everything posted by kurt.santo

  1. Thats good to know. Thanks for all inputs...Kurt
  2. Do you know why they wrap it up in two <script /> tags?Kurt
  3. I have a code given by Google to include in website code, but I would like to understand first what it does. The code is: <script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script><script type="text/javascript">var pageTracker = _gat._getTracker("UA-1982198-7");pageTracker._initData();pageTracker._trackPageview();</script> Does someone know what it does and is this to be
  4. I thought about a loop before, but then the problem comes in tha the db query should only be run once. I really do not have a clue in how to amend that it loops through my images, but it only does once db insert query. The code as it is: if (isset($_FILES['img1'])) { // validate the input global $ext; global $ext2; if(in_array($ext, $allowed) && in_array($ext2, $allowed)) { // move the file over if(move_uploaded_file($_FILES['img1']['tmp_name'], "{$images}{$img1}")) { echo '<p>file 1 has been uploaded ok</p>'; } else { echo '<p>file 1 upload did not wo
  5. Corrected and page displays. But now I realise another conceptual error I made. For the upload to work fine both files have to be uploaded. THis is not what I want. Only one is mandatory ($img1). Can I somehow amend line:if(in_array($ext, $allowed) && in_array($ext2, $allowed)) { so it only tests for $ext2 if $img2 is not FALSE (which is the complete file name including extension if it passed validation)?Kurt
  6. Use now: $ext = explode('.',$_FILES['img1']['name']); $ext = $ext[count($ext)-1]; which seems to do the trick... Thank you!Kurt
  7. I use the following code to move two files to permanent location while inserting their name in db table. IT works fine as long as you do not try to upload the wrong file type for second file. // check for img1 if (!isset($_FILES['img1']['name']) OR empty($_FILES['img1']['name'])) { $errors['img1'] = '\'Image 1\' is a required field'; $img1 = FALSE; } else { $ext = explode('.',$_FILES['img1']['name']); $ext = $ext[count($ext)-1]; if (!in_array($ext, $allowed)) { $errors['img1'] = '\'Image 1\' accepts only jpg and gif'; $img1 = FALSE; } else { $img1 = $user_id . '-1.' . $ext; } }
  8. Thanks, thats great. Will test and amend it later on to see if I can modify to fullfill my tasks. Cheers,Kurt
  9. Wander,Thanks for your input. That sounds like what I am after, but where would I put the functions to check for max height/width and resize? Still cannot get my head around in how to apply functions to variables. Maybe there is a complete example code somewhere of sth similar?Kurt
  10. It is an upload file in an area where you have to log in with username and password. Would hope folks do not try dodgy stuff, but then hey... What do I know. Check it a bit more in detail. Thanks for the info.Kurt
  11. Saw that, but as I do not know beforehand what image type folks upload am not sure in how to approach (have an array of allowed files)...Kurt
  12. I use a single table as I only want user to upload the max number of files and as I said if they upload a new file into one column to update the relevant column only. With the current system the user can use upload file and upload 100 files from same input. This means not only that there are a lot of rows for that user in table, but also that our server gets cluttered with unnecessary files...Kurt
  13. How do you move files into their permanent location if the varibles have different name (img1, img2, logo)? I use one file ok with: // move the file over if(move_uploaded_file($_FILES['img1']['tmp_name'], "{$images}/{$img1}")) { echo '<p>the file has been uploaded ok</p>'; } else { echo '<p>the file upload did not work</p>'; } Not all fields are nessesary to upload.Kurt
  14. Having a form where user can upload image files (currently just one) I need to test for a maximum height and width and decrease size if it exceeds the limit. In addtion a thumbnail also needs to be created and both put into separate folders. I found few functions, which can resize an image, but am not sure how to put the whole thing into my file. The relevant code currently is: // check for img1if (!isset($_FILES['img1']['name']) OR empty($_FILES['img1']['name'])) { $errors['img1'] = '\'Image 1\' is a required field';$img1 = FALSE;} else {$ext = explode('.',$_FILES['img1']['name']);$ext = $e
  15. Have a simple insert into db table as:$query = "INSERT INTO imgTest (user_id, img1, active) VALUES ('$user_id', '$img1', 'n')";This query creates each time a row the query is executed. I would like to have only one single row per user (later on I will add more fields to table) and if there is already an entry for this particular column to update column with file name and move new file into image folder as usual deleting old file.I move the file as: if(move_uploaded_file($_FILES['img1']['tmp_name'], "{$images}/{$img1}")) { echo '<p>the file has been uploaded ok</p>'; } else {
  16. Wanda,Take it all back. Saw finally my mistake and the following code is working well: $errors = array(); // check for img1 if (!isset($_FILES['img1']['name']) OR empty($_FILES['img1']['name'])) { $errors['img1'] = '\'Image 1\' is a required field'; $img1 = FALSE; } else { $ext = explode('.',$_FILES['img1']['name']); $ext = $ext[count($ext)-1]; if (!in_array($ext, $allowed)) { $errors['img1'] = '\'Image 1\' accepts only jpg and gif'; $img1 = FALSE; } else { $img1 = $user_id . '-1.' . $ext; } } if (isset($_FILES['img1'])) { // validate the input global $ext; if (in_array($ext
  17. Wanda,Thanks. To use explode works well to produce the file name. Still, having amended my $allowed array to read:$allowed = array ('gif', 'jpeg', 'jpg');and replacingif (in_array($_FILES['img1']['type'], $allowed)) {withglobal $ext; // as $ext is in if clauseif (!in_array($ext, $allowed)) {it does not let me upload/move a file of correct extension complaining that it is not gif or jpg (my own error message). When I do a dump of $ext it shows NULL. As it takes the right extension for name I do not get why it cannot use it for db insertion/moving. Do you know why that is?Kurt
  18. Having had two inputs on thread "Test for image type" showing me that I should not rely on browser giving me info about the file type I checked for finfo_file (I also checked for comment of Schraalhans Keukenmeester) and also for image_type_to_extension. My problem is a quite basic one, but I really do not know how to do it. Having for instance the following function: if(!function_exists('image_type_to_extension')){ function image_type_to_extension($imagetype,$include_dot=true) { if(empty($imagetype)) return false; $dot = $include_dot ? $dot.'' : ''; switch($imagety
  19. Wander,Thanks for the input. I am very grateful you helped me resolve this obstacle (thought I am going mad or so;-))...Kurt
  20. Wanda,You made my day! Using "/" instead of "\" does the trick. Actually, I cannot believe I haven't noticed this before... Only strange that for the tag without attributes it also worked the other way:echo "<br /><img src=\"images\a.gif\" alt='getimagesize() example 2' />";Do you know why this is the case?Kurt
  21. It is working when I place gif in same folder and change code accordingly. As soon as I place in subfolder it does not work again. As you can see from the following code, the image is in the folder:list($width, $height, $type, $attr) = getimagesize("images\a.gif");echo "<img src=\"images\a.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />";print_r(getimagesize("images\a.gif")); echo "<br /><img src=\"images\a.gif\" alt='getimagesize() example 2' />"; //this one shows on web page$File = file_get_contents("images\a.gif");echo $File; Kurt
  22. I amended the type array to:$allowed = array ('image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg');and it does the trick. But this is not what you meant, is it? Do you mean sth as:if(!function_exists('image_type_to_extension')){ function image_type_to_extension($imagetype) { if(empty($imagetype)) return false; switch($imagetype) { case IMAGETYPE_GIF : return 'gif'; case IMAGETYPE_JPEG : return 'jpg'; case IMAGETYPE_PNG : return 'png'; default : return false; } }} If yes, where and when w
  23. Thanks, Ingolme. Tried this already with same result...Kurt
  24. Sorry, that was just a transfer mistake. Problem still the same. I insert a code below that shows that if you leave width and height out it displays (although print_r does not display a thing). The code is:list($width, $height, $type, $attr) = getimagesize("images\a.gif");echo "<img src=\"images\a.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />";print_r(getimagesize("images\a.gif")); echo "<br /><img src=\"images\a.gif\" alt='getimagesize() example 2' />"; With source code as: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
  25. GD is installed as:GD Support enabled GD Version bundled (2.0.34 compatible) Also, before I go crazy in the coconut I have made the file as simple as possible. It reads now: <?php error_reporting (E_ALL);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><?phplist($width, $height, $type, $attr) = getimages
×
×
  • Create New...