Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How To Display Uploaded Images And Other Datas Using Php And Mysql

max_file_size mysql

  • Please log in to reply
1 reply to this topic

#1 lakeside

lakeside

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts
  • Programming Language:PHP
  • Learning:PHP

Posted 10 July 2012 - 06:26 AM

This is my form. I have been able to upload the image and the data entry into mysql database
and I wanted to preview the information with the uploaded image so that Applicant can print out the copy of registration form.
kindly help with the code to preview the information. Thank you

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<tr>
<td><input type="text" name="first_name" value="<?php echo $_SESSION['first_name'] ; ?>"/></td></tr>
<tr><td><input type="text" name="last_name" /><td></tr>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>



<?php

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{

$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];


$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}

$tmpName = $_FILES['userfile']['tmp_name'];
list($width, $height, $type, $attr) = getimagesize($tmpName)
if($width>400 || $height>425) {
die("exceeded image dimension limits.");
}
$fileSize = $_FILES['userfile']['size'];
if ($fileSize > 40000){
die("exceded image size limits");
}
$fileType = $_FILES['userfile']['type'];
if($fileType =="image/jpeg" || $fileType =="image/jpg" || $fileType =="image/pjpeg" || $fileType =="image/gif" || $fileType =="image/png"){

if (empty($errors)){
// Perform Update

$first_name = mysql_prep($_POST['first_name']);
$last_name = mysql_prep($_POST['last_name']);



$query = "INSERT INTO upload (name, size, type, content, first_name, last_name) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$first_name', '$last_name')";
}


Please how do i preview the information and uploaded image. thank you very much

Edited by Alexander, 10 July 2012 - 08:55 AM.
PHP tags, separated code

  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 10 July 2012 - 08:45 AM

You will have to refrain from submitting the information to the database on the same page. You should handle the files and print all the necessary information required on to the screen for them to review, print and confirm.

On the form to confirm you can place hidden fields with the necessary information to enter the database (<hidden name="..." value="..."/>) and these will be available on the next page. There are other methods such as cookies, or storing it in the database and giving it an ID (a temporary entry) that can be retrieved on the next page and submitted properly once confirmed.

i.e.
  • user submits form
  • print information, store in temporary database row, retrieve id of it
  • user confirms (or cancels) sending id with form
  • information is submitted, user is given confirmation of success.

Alexander.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.






Also tagged with one or more of these keywords: max_file_size, mysql

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download