This is the code I use to upload an image to my database and my ftp it works great but I want to be able to set the max width and max height, how can I do that?
In header
PHP Code:<?php
session_start();
include("connect_to_mysql.php");
if (!isset($_SESSION['sess_user'])){
header("Location: index.php");
exit;
}
if (isset($_GET['logout'])){
session_unset();
session_destroy();
header("Location: index.php");
exit;
}
$upload_dir = 'files/';
$filetypes = 'jpg,jpeg,gif,png,bmp';
if(isset($_POST['submit'])) {
$userfile = $_FILES['userfile']['name'];
$types = explode(',',$filetypes);
$file = explode('.',$_FILES['userfile']['name']);
$extension = $file[sizeof($file)-1];
if(!in_array($extension,$types)) {
if($IngenBildSiffra == 1) {
echo "";
} else {
$notAllowedFileType = 1;
}
}
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_dir.$_FILES['userfile']['name']);
}
$sql = "INSERT INTO CMS_bild (image) VALUES ('$userfile')";
mysql_query($sql);
header("Location: botright.php?sent");
exit();
}
?>
<script type="text/javascript">
function submit_form(valVar) {
// Sätter vald åtgärd till 'true'
document.getElementById(valVar).value = 'true';
document.getElementById('formName').submit();
}
<?php
if ($added == 1){
echo "alert('Uppdateringen skedde utan problem.');\r\n";
$header = 1;
}
?>
// -->
</script>
On page
PHP Code:<?php
if(isset($_GET['sent'])) {
echo "Bilden <strong>".$_FILES['userfile']['name']."</strong> laddades upp utan problem!<br>";
}
if(isset($_GET['imageexist'])) {
echo "Bilden existerar redan.<br>";
}
}
?>
</td>
</tr>
</table>
</div>
<form method="post" action="<? echo "".$_SERVER['PHP_SELF'].""; ?>" enctype="multipart/form-data">
<tr>
<td>
Bild
</td> <td><input type="file" name="userfile" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" / value="Lägg upp bild"></td>
</tr>
</table>
</form>


Reply With Quote

Bookmarks