Jump to content

kurt.santo

Members
  • Posts

    925
  • Joined

  • Last visited

kurt.santo's Achievements

Invested Member

Invested Member (3/7)

0

Reputation

  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 included in all pages of that website?Thanks,Kurt
  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 work</p>'; } if(move_uploaded_file($_FILES['img2']['tmp_name'], "{$images}{$img2}")) { echo '<p>file 2 has been uploaded ok</p>'; } else { echo '<p>file 2 upload did not work</p>'; } // add the data $query = "INSERT INTO imgTest (user_id, img1, img2) VALUES ('$user_id', '$img1', '$img2')"; $result = mysqli_query ($dbc, $query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysqli_affected_rows($dbc) == 1) { // If it ran ok echo "db insertion went ok"; } else { // if it did not run ok echo '<p>Your data could not be uploaded due to a system error. We apologise for any inconvenience.</p>'; } } else { // if one of the data tests failed echo '<p>You forgot to upload required data or there is a problem with the given input. Please amend the highlighted fields.</p>'; Can you see what I mean?Kurt
  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; } } // check for img2 if (!isset($_FILES['img2']['name']) OR empty($_FILES['img2']['name'])) { $errors['img2'] = '\'Image 2\' is a required field'; $img2 = FALSE; } else { $ext2 = explode('.',$_FILES['img2']['name']); $ext2 = $ext2[count($ext2)-1]; if (!in_array($ext2, $allowed)) { $errors['img2'] = '\'Image 2\' accepts only jpg and gif'; $img2 = FALSE; } else { $img2 = $user_id . '-2.' . $ext2; } } if (isset($_FILES['img1'])) { // validate the input global $ext; if (in_array($ext, $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 work</p>'; } if(move_uploaded_file($_FILES['img2']['tmp_name'], "{$images}{$img2}")) { echo '<p>file 2 has been uploaded ok</p>'; } else { echo '<p>file 2 upload did not work</p>'; } // add the data While only $img1 is required I still need to check for valid file types before moving and inserting in db (therefore line if (in_array($ext, $allowed)) ). With this way it does only work if the file type for $img2 is correct. Otherwise, there will be error messages as $img2 is FALSE (from my validation routine before). How can I amend line:if (in_array($ext, $allowed)) {to also check for $ext2? I tried:if (in_array($ext, $allowed)) && (in_array($ext2, $allowed)) {but the page won't even display...Any ideas?Kurt
  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 = $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, $allowed)) { // 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>'; } // add the data $query = "INSERT INTO imgTest (user_id, img1) VALUES ('$user_id', '$img1')"; $result = mysqli_query ($dbc, $query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysqli_affected_rows($dbc) == 1) { // If it ran ok echo "db insertion went ok"; } else { // if it did not run ok echo '<p>Your data could not be uploaded due to a system error. We apologise for any inconvenience.</p>'; } } else { // if one of the data tests failed echo '<p>You forgot to upload required data or there is a problem with the given input. Please amend the highlighted fields.</p>'; } }} else // Please upload your data message etc
  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 { echo '<p>the file upload did not work</p>'; } Has anyone done such a thing and can share the experience?Kurt
×
×
  • Create New...