Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is this code can upload images??

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
Am trying to upload images using the following code:

myfotos.php:

<?php

//connection and header go here

$split = explode(&quot;.&quot;, $photo_name);
$ext = strtolower($split[1]);

if ($ext == &quot;jpg&quot; || $ext == &quot;gif&quot; || $ext == &quot;jpeg&quot;) {
$time = time();
$file = &quot;images/$time-$photo_name&quot;;
move_uploaded_file($photo, &quot;$file&quot;);
}

if($submit){
mysql_query(&quot;INSERT INTO fototbl (name,foto) VALUES ('$name','$file')&quot;)or die (&quot;Error in query: $query. &quot; . mysql_error()) ;
}

?>

<form action=&quot;myfotos.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>

<td><input type=&quot;text&quot; name=&quot;name&quot;></td>

<td><input type=&quot;file&quot; class=&quot;input&quot; name=&quot;file&quot;>

<td><input type=&quot;submit&quot; value=&quot;Send&quot; name=&quot;submit&quot;></td>

</form>

When I checked the table fototbl, I found the data in the name field is perfect, but in the foto field I found: /tmp/phpSTFJV9
and the image was not uploaded to images directory.

Any help please?
Thanks in advance
 
PHP does not store the file in the upload temp directory using the name of the file you uploaded nor the name of the form field. It hashes the filename to prevent collisions. So you need to make use of the $_FILES superglobal in your code.

Read the manual section on handling file uploads ( ______________________________________________________________________
TANSTAAFL!
 
also, instead of using explode, use getimagesize (see PHP docs for more about it)
cause right now if you try to upload a file name photo.old.jpg, it will take .old as the extension ...
Khaldryck
Programmer at the University of Brussel (Belgium)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top