By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Upload->resize->pathname in Mysql

P: 1
Hello everyone,

I am new in PHP-programming but I am learning the basics of it.
I've got a script that uploads a picture together with all data from the inputform, to the server and places the pathname into the Mysql.
I desperately want to have the uploaded pictures resized in the meantime.
Does anyone know how to do this ? Or perhaps adjust the script with the functions, necessary for resizing ?

I would appreciate it VERY VERY much !
Thank you !!

script :
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('../Connections/tutorial.php'); ?>
  2. <?php
  3. mysql_select_db($database_tutorial, $tutorial);
  4. $query_Recordset1 = "SELECT * FROM tut_afbeelding";
  5. $Recordset1 = mysql_query($query_Recordset1, $tutorial) or die(mysql_error());
  6. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  7. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  8.  
  9. mysql_select_db($database_tutorial, $tutorial);
  10. $query_Recordset2 = "SELECT distinct job FROM tut_afbeelding";
  11. $Recordset2 = mysql_query($query_Recordset2, $tutorial) or die(mysql_error());
  12. $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  13. $totalRows_Recordset2 = mysql_num_rows($Recordset2);
  14.  
  15.  
  16. require_once('config.php');
  17. include ("filter.php");
  18. $go = $_POST['go'];
  19. if ($go ==""): 
  20.  
  21. ?>
  22.  
  23. </head>
  24. <body>
  25. <form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
  26.  
  27. <!-- Hier komt het verborgen veld 'go met de waarde 'go' -->
  28.    <input name="go" type="hidden" value="go">
  29.        <table width="450" border="0" bgcolor="#99CCFF" align="center">
  30.        <tr>
  31.          <td bgcolor="#99CCFF">Naam</td>
  32.          <td valign="baseline"><input name="naam" type="text" id="naam" value="" size="32"></td>
  33.        </tr>
  34.     <tr>
  35.       <td bgcolor="#99CCFF">Job</td>
  36.       <td valign="baseline"><select name="job" id="job">
  37.         <?php
  38. do {  
  39.  
  40.         <option value="<?php echo $row_Recordset2['job']?>"<?php if (!(strcmp($row_Recordset2['job'], $row_Recordset2['job']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset2['job']?></option>
  41.         <?php
  42. } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  43.   $rows = mysql_num_rows($Recordset2);
  44.   if($rows > 0) {
  45.       mysql_data_seek($Recordset2, 0);
  46.       $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  47.   }
  48.  
  49.         </select>
  50.       </td>
  51.     </tr>
  52.     <tr>
  53.       <td bgcolor="#99CCFF">Plaats</td>
  54.       <td valign="baseline"><input name="plaats" type="text" id="plaats" value="" size="32"></td>
  55.     </tr>
  56.     <tr>
  57.       <td bgcolor="#99CCFF">Hobby</td>
  58.       <td valign="baseline"><input name="hobby" type="text" id="hobby" value="" size="32"></td>
  59.     </tr>
  60.     <tr>
  61.       <td bgcolor="#99CCFF">Omschrijving</td>
  62.       <td><input name="omschrijving" type="text" id="omschrijving" size="50"></td>
  63.     </tr>
  64.     <tr>
  65.       <td bgcolor="#99CCFF">Afbeelding</td>
  66.       <td><input name="afbeelding" type="file" accept="image/jpeg" id="afbeelding" size="50"></td>
  67.     </tr>
  68.     <tr>
  69.       <td bgcolor="#99CCFF">&nbsp;</td>
  70.       <td><input type="submit" name="Submit" value="Verzenden">
  71.       <input type="reset" name="Reset" value="Herstellen"></td>
  72.     </tr>
  73.   </table>
  74.   <p>&nbsp;</p>
  75. </form>
  76.  
  77.  
  78. endif;
  79.  
  80.  
  81.  
  82.  
  83. if ($go =="go"):
  84.  
  85. $hello = getcwd();
  86.  
  87.  
  88. $file_dir = ($hello . "/images/");
  89.  
  90.  
  91. if (is_dir ($file_dir)) {
  92.   print "<br><br>++directorty bestaat";  
  93.   }  else {  
  94.   print "<br><br>--Directory bestaat nog niet" . $file_dir;  
  95.     $newpage = $file_dir;
  96.     echo ("<br>we gaan daarom de directory aanmaken");
  97.     mkdir ($newpage, 0777);    
  98.   }  
  99.  
  100.  
  101. echo date("m/d/y G.i:s");
  102.  
  103.  
  104. echo ("<br><br>");
  105.  
  106. foreach($_FILES as $file_name => $file_array) {
  107.  
  108.        $file_name=str_replace("'", "_", $file_array['name']);
  109.        $file_name=str_replace(" ", "_", $file_array['name']);
  110.        $file_name=stripslashes ($file_name);
  111.        $file_name=trim($file_name);       
  112.        $file_name=strtolower($file_name);    
  113.  
  114.        echo "path: " .$file_array['tmp_name'] . "<br>\n";
  115.        echo "name: " .$file_name . "<br>\n";    
  116.        echo "type: " .$file_array['type'] ."<br>\n";
  117.        echo "size: " .$file_array['size'] ."<br>\n";
  118.  
  119.  
  120.        $test = afbeeldingen($file_name);
  121.        if ($test !=""):
  122.             echo $file_name . " dit is een afbeelding<br>";
  123.             if (is_uploaded_file($file_array['tmp_name'])) {
  124.  
  125.                  move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_name") or die ("Couldn't copy");
  126.                  echo "Afbeelding staat op de server<br><br>";
  127.  
  128.                  $afbeelding = "images/" . $file_name;
  129.                  $query = "INSERT INTO tut_afbeelding (ID, naam, job, plaats, hobby, omschrijving, afbeelding) VALUES ('', '$_POST[naam]', '$_POST[job]', '$_POST[plaats]', '$_POST[hobby]', '$_POST[omschrijving]','$afbeelding')";    
  130.                     if(!mysql_db_query($dbname,$query,$db)) die(mysql_error());                      
  131.                         echo $afbeelding . " is toegevoegd aan de database met als omschrijving : <br>";                    
  132.                         echo $_POST[omschrijving] ;
  133.             }
  134.        endif;                     
  135.        if ($test ==""):    
  136.              echo $file_name . " dit is geen afbeelding en wordt daarom niet op de server geplaatst<br>\n";      
  137.        endif;
  138.   }
  139. endif;
  140.  
  141.  
  142.  
  143. mysql_free_result($Recordset1);
  144.  
  145. mysql_free_result($Recordset2);
  146. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jul 3 '07 #1
Share this Question
Share on Google+
1 Reply


kovik
Expert 100+
P: 1,044
Image resizing can easily be done using the GD library with the imagecoypresampled() function.
Jul 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.