logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 11-01-2012, 05:04 PM   #1
Dino173
 
Join Date: Nov 2012
Posts: 2
Default PHP image upload help

Hi all, i have been having trouble with uploading an image from a form, using this images location to store it into MySQL.

PHP Code:
<?php

// Include database connection file
include('../inc/connection.inc.php');

// Check to see if the form has been submitted
if (isset($_POST['submit']))
{
     
//This is the directory where images will be saved 
 
$target "../images/avatars"
 
$target $target basename($_FILES['photoLocation']['name']);
    
    
// Check to see all fields have been completed
    
$photoLocation =($_FILES['photoLocation']['name']);
    
$name $_POST['name'];
    
$reason $_POST['reason'];
    
$whatPub $_POST['whatPub'];
    
$expire $_POST['expire'];
    
    if (!empty(
$photoLocation) && !empty($name) && !empty($reason)&& !empty($whatPub)&& !empty($expire))
    {
        
// Create an SQL query to add the comment
        
$sql "INSERT INTO tblPhotoUpload (photoLocation, name, reason, whatPub, expire) VALUES ('$photoLocation', '$name', '$reason', '$whatPub', '$expire')";


        
// Connect to the database
        
connect();
        
        
// Run the query and store the result in a variable
        
$result mysql_query($sql) or die("Could not run query");
        
        
// Close connection to the database
        
mysql_close();
        
        
//Writes the photo to the server 
         
if(move_uploaded_file($_FILES['photoLocation']['tmp_name'], $target))
        
        
// Check if query was successful

 
        
if ($result)
        {
            
$message '<div class="success"><p>Thank you for your upload.</p><p>Please <a href="./index.php">Click Here</a> to view the uploads</p></div>';
        }
        else
        {
            
$message '<div class="error"><p>There was an error adding your upload, please try again</p></div>';
        }
    }
    else
    {
        
$message '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
    }
}
?>
PHP Code:
<p>Please enter the banned person and click submit</p>
        
        <form enctype="multipart/form-data" name="addBanderPerson" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">

<?php
    
if (isset($message))
    {
        echo 
$message;    
    }
?>
        
  <div class="label"><label for="photoLocation">Upload a Photo:</label></div>
  <div class="input"><input type="file" name="photoLocation" id="photoLocation" tabindex="1" /></div>
  <br />
  <div class="label"><label for="name">Name:</label></div>
  <div class="input"><input type="text" name="name" id="name" tabindex="2" /></div>
  </div>
  <br />
  <div class="label"><label for="reason">Reason:</label></div>
  <div class="input"><input type="text" name="reason" id="reason" tabindex="3" /></div>
  <br />
  <div class="label"><label for"whatPub">Waht Pub:</label></div>
  <div class="input"><input type="text" name="whatPub" id="whatPub" tabindex="4" /></div>
  <br />
    <div class="label"><label for"expire">Expire:</label></div>
  <div class="input"><input type="text" name="expire" id="expire" tabindex="5" /></div>
  <br />
  <div class="input">
    <input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
    <input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />
  </div>
  
</form>
the error message i get when running it is.


Warning: move_uploaded_file(../images/avatarsChrysanthemum.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/dsmith/public_html/HebburnAndJarrowPubWatch/admin/addBanderPerson.php on line 36

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpHPUyXz' to '../images/avatarsChrysanthemum.jpg' in /home/dsmith/public_html/HebburnAndJarrowPubWatch/admin/addBanderPerson.php on line 36

any help or suggestions would be great.
Dino173 is offline   Reply With Quote
Old 11-02-2012, 01:20 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

check your permissions on the folders , they should have write permission
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-02-2012, 10:32 AM   #3
Dino173
 
Join Date: Nov 2012
Posts: 2
Default

Thanks for the reply.

I have checked the permissions and i have full access to the folders and sub folders.
Dino173 is offline   Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:46 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com