Advertisement

02.17.2004 at 08:19PM PST, ID: 20888777
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

PHP Upload image

Tags: php, upload, image
Dear all,

I have looked around and it been frustrating for the  past 3 hrs....I would liek to the scripts for a form which would help me upload image files onto teh server.

So basically, should have 2 files:

A form for browsing my PC and choosing an image which is submitted to a php file This php file apart from uploading the image onto my server will also provide me with details on the file size, etc which will be dispalyed.

Now, i knw thr are loads of scripts, but i always get the error stsating tht teh stream for the image is not found...i suspect that the image file isint being passed well  frm the form to the php file...

can someone help me with a full working code.

thanks.

with regards,
karthik
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: cancerkats
Solution Provided By: waygood
Participating Experts: 2
Solution Grade: A
Views: 412
Translate:
Loading Advertisement...
02.18.2004 at 07:25AM PST, ID: 10393238

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.18.2004 at 07:27AM PST, ID: 10393264

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.28.2004 at 01:05AM PST, ID: 10475188

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.28.2004 at 07:41AM PST, ID: 10476263

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.04.2004 at 06:34AM PST, ID: 10514145

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.04.2004 at 08:42AM PST, ID: 10515460

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.04.2004 at 08:49AM PST, ID: 10515518

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.05.2004 at 01:24AM PST, ID: 10521068

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.05.2004 at 02:02AM PST, ID: 10521225

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.05.2004 at 11:47PM PST, ID: 10529910

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.08.2004 at 01:36AM PST, ID: 10539182

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.18.2004 at 07:25AM PST, ID: 10393238
Quick example

<form name="file_upload" method="post" action="process.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="file" name="form_image" />
</form>


----------------

<?php

if(is_uploaded_file($_FILES['form_image']['tmp_name']))
{
  // file uploaded to server
  echo "file information is :-<br />";
  print_r($_FILES);

      $imageInfo = getimagesize($_FILES['form_image']['tmp_name']);
      $width = $imageInfo[0];
      $height = $imageInfo[1];
      $image_type = $imageInfo[2];
      print_r($imageInfo );

  // move_uploaded_file($_FILES['form_image']['tmp_name'], "./tempfile/".$_FILES['form_image']['tmp_name']);

}
else
{
  // file not uploaded to server
}
 
02.18.2004 at 07:27AM PST, ID: 10393264
the move_uploaded_file was supposed to have ['name'];  at the end not ['tmp_name'];
 
02.28.2004 at 01:05AM PST, ID: 10475188
Hi waygood,

Your example has proved to be a great help. However, I have some more problems.

1. When I tried to insert the $imageInfo into my table, it shows "array" instead of the name of my file (e.g. image.jpg).

2. I have a textarea for the posting of the image description. But I haven't been able to grab the description and insert it into the gallery table.

I would appreciate anyone's help.

--- Table ---
Gallery table has 3 fields:
id(primary key)
image(for the uploading of image file)
imageDescription(a description for the image file)

--- gallery_upload form ---
<form action="gallery_insert.php" method="post" enctype="multipart/form-data">
  <p>Note: All fields are mandatory / compulsory. Please fill them all up.
  </p>
  <p>Description:<br>
    <textarea name="imageDescription" rows=4 cols=70></textarea>
  </p>
  <p>Upload a photo(gif/jpeg format) for this event: <br>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <input name="image" type="file" size="70">
  </p>
  <p>
    <input type="submit" value="Send this file!">
  </p>
</form>

--- gallery_insert.php ---
if(is_uploaded_file($_FILES['image']['tmp_name']))
{
  // file uploaded to server
  echo "file information is :-<br />";
  print_r($_FILES);

     $imageInfo = getimagesize($_FILES['image']['tmp_name']);
     $width = $imageInfo[0];
     $height = $imageInfo[1];
     $image_type = $imageInfo[2];
     print_r($imageInfo);

  move_uploaded_file($_FILES['form_image']['tmp_name'], "./tempfile/".$_FILES['form_image']['name']);

//Insert record into database
$insert_data = "INSERT INTO gallery VALUE
                      ('', '$imageInfo' , '$imageDescription')";
}
else
{
      echo "No image was uploaded!";
}      
            
if (mysql_query($insert_data,$db)) {
echo "Record added";
}
else {
echo "No record was added";
}
 
02.28.2004 at 07:41AM PST, ID: 10476263
as you can see from the code

     $width = $imageInfo[0];
     $height = $imageInfo[1];
     $image_type = $imageInfo[2];
     
$imageInfo IS an array, you need to specify which elements you want, when doing your insert.

e.g.
$insert_data = "INSERT INTO gallery VALUE
                      ('', '".$imageInfo[3]."' , '$imageDescription')";
NB I always seperate the variables from the text as there is a problem with array elements when doing it your way.    $text="text".$var[0]."text";

print_r($imageInfo);  will show your the array structure and the info it contains
 
03.04.2004 at 06:34AM PST, ID: 10514145
Hi waygood,

can you give a clearer example of how to "grab" an appropriate image name into the variable $imageInfo? I have tried it out many times but still couldn't find an answer myself.

For example, I want to upload "a.gif" from my local computer into the mysql table. I upload it through my gallery_upload.htm form, which in turn calls for gallery_insert.php. I want my variable $imageInfo to appear as exactly "a.gif". I would appreciate if you can give me a full working code.

Thanks in advance.
 
03.04.2004 at 08:42AM PST, ID: 10515460
imageInfo contains information relating to an image ie size and type, because you use the function getimagesize to gather it.
The file information can be found within $_FILES

getimagesize
---------------
Returns an array with 4 elements.
Index 0 contains the width of the image in pixels.
Index 1 contains the height.
Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.
Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

$_FILES
---------
$_FILES['userfile']['name']  The original name of the file on the client machine.
$_FILES['userfile']['type']  The mime type of the file, if the browser provided this information. An example would be "image/gif".
$_FILES['userfile']['size']  The size, in bytes, of the uploaded file.
$_FILES['userfile']['tmp_name']  The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES['userfile']['error']  The error code associated with this file upload. ['error'] was added in PHP 4.2.0

from my first comment (adjusted a little):-
 move_uploaded_file($_FILES['form_image']['tmp_name'], "./upload_dir/".$_FILES['form_image']['name']);

where the directory 'upload_dir' is in the current directory where your script id being run.
moves the uploaded file (which is stored under a temp name to prevent over-writing other peoples) from the temp directory where all uploads are temporary stored to your directory (upload_dir) and renamed to the original name.
 
03.04.2004 at 08:49AM PST, ID: 10515518
$insert_data = "INSERT INTO gallery VALUE
                      ('', '$imageInfo' , '$imageDescription')";
should be

$insert_data="INSERT INTO gallery VALUES ('', '".$_FILES['image']['name']."', '".$_POST['imageDescription']."')";
 
03.05.2004 at 01:24AM PST, ID: 10521068
Thanks a lot, waygood for your valuable comments.

Now that I am able to successfully "grab" all the data from my gallery_upload form and insert them appropriately into the gallery table.

However, I face another problem. When I try to view the image uploaded through a php file (gallery_view.php), I see only the name of the uploaded file (e.g. a.gif) instead of the image itself. I probably guessed this would have happened. Can you give me directions?  

--- gallery_view.php ---
<?php

include 'db.inc';

//Connect to the database
$db = @mysql_connect($hostName, $username, $password);
@mysql_select_db($databaseName, $db);

//Test to see if connected to database
echo "$db";

//Create and execute the sql statement and get the values from the result set
$get_image="Select image FROM gallery where id=$id";
$get_image_result=@mysql_query($get_image);

$image=@mysql_result($get_image_result,0,"image");

echo "$image";

?>
 
03.05.2004 at 02:02AM PST, ID: 10521225
to display an image on a web page you need to use img, echo will just send the info to the page.

echo '<img src="'.$image.'" />';

If you store the image info index3 then you will have the dimensions.

$image=mysql_fetch_assoc($get_image_result);
echo '<img src="'.$image['name'].'" '.$image['dimensions'].' />';

this will give you something like <img src="a.gif" width="120" height="342" />
 
03.05.2004 at 11:47PM PST, ID: 10529910
Waygood,

I have tried out the above script that you suggested. But it still doesn't seem to work. However, instead of the "a.gif" which is seen earlier, echo '<img src="'.$image.'" />'; now returns a box with the "x" sign (probably because the image source cannot be found?)

In your opinion, what might have been the problem? Any solutions to enable the image to show?

--- gallery_view.php ---
<?php

include 'db.inc';

//Connect to the database
$db = @mysql_connect($hostName, $username, $password);
@mysql_select_db($databaseName, $db);

//Test to see if connected to database
echo "$db";
echo "<br>";

//Create and execute the sql statement and get the values from the result set
$get_image="Select       image
          FROM       gallery
          WHERE       image='calendar.gif'";

$get_image_result=@mysql_query($get_image);
$image=@mysql_result($get_image_result,0,"image");
$image=mysql_fetch_assoc($get_image_result);

echo '<img src="'.$image['name'].'" '.$image['dimensions'].' />';

?>
 
03.08.2004 at 01:36AM PST, ID: 10539182
where are you storing the picture?    move_uploaded_file(source, destination);

the temp file can be temporary viewed with
echo '<img src="'.$image['tmp_name'].'" '.$image['dimensions'].' />';

but this will be deleted after a time, so move it to your uploaded images folder and dont forget to include the directory name when using the img tag

eg.
move_uploaded_file($image['tmp_name'], "./uploaded_images/".$image['name']);
echo '<img src="./uploaded_images/'.$image['name'].'" '.$image['dimensions'].' />';




Accepted Solution
 
 
20080236-EE-VQP-29