Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Image upload


Image upload

Closed Thread
  #1 (permalink)  
Old 12-19-09, 01:44 PM
SniperTowers SniperTowers is offline
Wannabe Coder
 
Join Date: Dec 2008
Posts: 143
Thanks: 5
Thanked 0 Times in 0 Posts
Image upload

PHP Code:

<?php

session_start
();
require (
"../connect.php");
require(
"../functions.php");

if(
$_SESSION['status'] != 2){
    echo 
"You do not have permission to access this area!";
    }
if(
$_SESSION['status'] == 2){
    echo 
"<h3>Add a Gift</h3>";

    if(!isset(
$_POST['submit'])){
        echo 
"<form action=\"\" method=\"post\">
            Title: <br/><input type=\"text\" name=\"title\" class=\"adminform\"><br/>
            Description: <br/><input type=\"text\" name=\"description\" class=\"adminform\"><br/>
            Referrals: <br/><input type=\"text\" name=\"referrals\" class=\"adminform\"><br/>
            Image (100px x 100px): <br/><input id=\"file\" type=\"file\" name=\"file\" />
            <br/><br/><input type=\"submit\" name=\"submit\" value=\"Add Gift.\">
              </form>"
;
        echo 
"<br/><br/><br/>";
    }else{
      
$rand rand(0,999999);
      
move_uploaded_file($_FILES["file"]["tmp_name"], "images/" "$rand$_FILES["file"]["name"]);
      
$image "$rand$_FILES["file"]["name"];
      if(empty(
$_FILES["file"]["name"])){
          
$image "none.jpeg";
      }
        
$title mysql_real_escape_string($_POST['title']);
        
$description mysql_real_escape_string($_POST['description']);
        
$referrals mysql_real_escape_string($_POST['referrals']);
    
    if(empty(
$title)){
        die (
'You have not filled in all the fields required!');
    }
    
mysql_query("INSERT into gifts VALUES(NULL, '$title', '$description', '$referrals', '$image')");
    echo 
"The gift with the title $title has been created!";
    }
    }
?>
My code is above. Everything uploads to the database fine except the image. The image stays as none.jpeg and the file doesn't upload into the folder either.

What am I doing wrong?
  #2 (permalink)  
Old 12-19-09, 03:27 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
I haven't had time to look at the code closely, but one thing I would say is to not use "title" as the name of a form field. It's a reserved keyword in HTML and may cause confusion.

If you print out the value of the "title" field (as a diagnostic), what does it output?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
  #3 (permalink)  
Old 12-19-09, 09:24 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Also, check the directory permissions of the target folder to ensure the server can write to it.
  #4 (permalink)  
Old 02-10-10, 07:17 AM
SweetDani SweetDani is offline
New Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I Also have no time to read all the code but I think When u coding just check the directoy permmission and also check the file ext. Try ant other image ext if you have some problem to uploading.

Thanks Dani
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
div css theighost CSS 11 09-14-08 02:30 AM
User Image Upload Script Phrozen44 Script Requests 12 07-16-08 12:15 AM
Simple image upload lewiscornwell Job Offers & Assistance 2 11-21-07 06:14 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
Image upload and if / else mdhall PHP 4 11-14-04 03:12 PM


All times are GMT -5. The time now is 08:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.