PDA

View Full Version : Upload image and 3 text boxes


Marco
01-08-2015, 03:44 PM
Hello to all!
My problem is that in one form i'd like to upload to my mysql database 3 text boxes and 1 image.
So, with dreamweaver CS5.5 i create module, and 3 text boxes joined to my mysql database. But when i create in the same module the "upload file", i can join this module only as "text" and not like "blob". How can i do?
Thanks in advance,
Marco

edbr
01-09-2015, 02:29 AM
better to upload the image to a folder and the image path to your database

edbr
01-09-2015, 02:36 AM
heres a simple upload script i swiped from a quick yahoogle search, it returns a path address ot the uploaded image so you should be able to modify it to suit
<?php
// Simple PHP Upload Script: http://coursesweb.net/php-mysql/

$uploadpath = 'upload/'; // directory to store the uploaded files
$max_size = 2000; // maximum file size, in KiloBytes
$alwidth = 900; // maximum allowed width, in pixels
$alheight = 800; // maximum allowed height, in pixels
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions

if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors

// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;

// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height;
echo '<br/><br/>Image address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>';
}
else echo '<b>Unable to upload the file.</b>';
}
else echo $err;
}
?>
<div style="margin:1em auto; width:333px; text-align:center;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
Upload File: <input type="file" name="fileup" /><br/>
<input type="submit" name='submit' value="Upload" />
</form>
</div>

neodev
01-13-2015, 02:55 PM
Please, I need help on this issue:
I have a database: there is a table (called "utenti") with 3 field: id, name and pic.
The pic field will store the path/image name that the images has in the server folder.
My problem is build an insert form that contain these fields, specially the last one (pic field).
The form will be a field text with the classic button "select" and another one "upload.
I would like that when I press "upload", the data insert in the name field go to the "name" database field, the pic will go to 2 different folder: one called "large" (with a specific resize in width") and the other one called "thumb" (with another resize "width").
In this case, the database will store only the path where the pis is stored (like "large/image.jpg") and (thumb/image.jpg).
To do that, I try to assemble the code of "tux" member (about his "PHP Image upload and resize" article) and yours, but I failed.

Please, colud you arrange an example for me?
Thanks a lot.