Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
upload image name to database, and actual file to directory HELP
Old 09-27-2010, 02:06 PM upload image name to database, and actual file to directory HELP
Average Talker

Posts: 26
Trades: 0
Can anyone point out/help as to why my script is not working for uploading an image to a directory and the name of the image to the database. At the moment once I submit the form, it goes to the script page but remains blank, i look in the database and nothing has happened...I have used a similar script on another one of my sites and it has worked but I have adjusted it slightly to this one.

Help would be greatly appreciated, as i can'd the root of the problem at all

Here is the form

PHP Code:
<form  action="uploadimage.php"  method="post" enctype="multipart/form-data" 
<
input type="file" name="image" /> 
<
br /> 
<
input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 
<
br /> 
<
input type="submit" id="submit" value="Upload"

</
form
and here is the uploadimage.php script

PHP Code:
<?php 

include "include/conn.php"

include 
"include/session.php"
?> 

<?php 


// Check to see if the type of file uploaded is a valid image type 
function is_valid_type($file

        
        
$valid_types = array("image/jpg""image/jpeg""image/bmp""image/gif"); 

        if (
in_array($file['type'], $valid_types)) 
                return 
1
        return 
0



function 
showContents($array

        echo 
"<pre>"
        
print_r($array); 
        echo 
"</pre>"





$TARGET_PATH "images/"

// Get POSTed variables 

$image $_FILES['image']; 


$image['name'] = mysql_real_escape_string($image['name']); 


$TARGET_PATH .= $image['name']; 

// Make sure all the fields from the form have inputs 
if ($image['name'] == "" 

        
$_SESSION['error'] = "All fields are required"
        
header("Location: addvox.php"); 
        exit; 


// Verify file is an image 
if (!is_valid_type($image)) 

        
$_SESSION['error'] = "You must upload a jpeg, gif, or bmp"
        
header("Location: addvox.php"); 
        exit; 




// move file into the directory and the path name into the database 
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) 

         
        
$sql "INSERT INTO images(image) VALUES ({$image['name']}) "
        
$result mysql_query($sql) or die ("Could not insert data into DB: " mysql_error()); 
        
header("Location: addvox.php"); 
        exit; 

else 

         
        
$_SESSION['error'] = "Could not upload file.  Check read/write persmissions on the directory"
      
        exit; 

?>
THANK U!
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-27-2010, 07:27 PM Re: upload image name to database, and actual file to directory HELP
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
I'm just going to take some troubleshooting guesses here... so no errors?

is the script connected to an sql database connection to user mysql_real_escape_string?

is the images/ folder chmodded?

i would try to put a echo 'hello'; somewhere near the top and keep testing the page... and moving it down until you can't see it to see how far the script has gone... assuming you had php errors on and it shows nothing
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 09-27-2010, 09:36 PM Re: upload image name to database, and actual file to directory HELP
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
Well, it seems like it's failing here:

if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))

So I'd guess that it has to do with your folder permissions... you should check 1) that it's uploading to the correct path, and 2) that the folder is chowned and chmodded properly.

Try this first:

$TARGET_PATH =
dirname(__FILE__) . "/images/";
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-28-2010, 03:53 AM Re: upload image name to database, and actual file to directory HELP
Average Talker

Posts: 26
Trades: 0
I havent got any folder permissions on as im just testing it locally, i mean the image is being moved into the folder, its just not working with the database.

I made the change you said and now I get an error saying 'Could not insert data into DB: Unknown column 'caparo' in 'field list''.
applebiz89 is offline
Reply With Quote
View Public Profile
 
Old 09-28-2010, 05:34 AM Re: upload image name to database, and actual file to directory HELP
Average Talker

Posts: 26
Trades: 0
ive worked it out, it was the was the select statement cheers guys
applebiz89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to upload image name to database, and actual file to directory HELP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21670 seconds with 12 queries