View Single Post
09-24-2012, 06:30 PM
#1
j-leist is offline j-leist
Status: I'm new around here
Join date: Sep 2012
Location: Leicester, England
Expertise: PHP, MySQL, HTML5, CSS3
Software: Dreamweaver!
 
Posts: 1
iTrader: 0 / 0%
 

j-leist is on a distinguished road

  Old  File Upload Script Only Working Occasionally

Hi,

Basically I have written a script to allow the user in the back end to upload pictures for the gallery. The script is supposed to upload the file to the server and then post the file name and info into the database.

It always uploads the file to the server without fail, however for some reason it only posts it to the database occasionally. Sometimes it works fine but 8 times out of 10 it uploads the file and thats it, the script is as follows.


PHP Code:
<?php 
 
 
//This is the directory where images will be saved 
 
$target "images/"
 
$target $target basename$_FILES['photo']['name']); 
 
 
//This gets all the other information from the form 
 
$name=$_POST['name']; 
 
$caption=$_POST['caption']; 
 
$pic=($_FILES['photo']['name']); 
 
$live=$_POST['live'];
 
 
//Connecting to the database
 
require_once('../Connections/tim.php'); 
 
 
 
//Writes the information to the database 
 
mysql_query("INSERT INTO `gallery` VALUES ('$name', '$caption', '$pic', '$live')") ; 
 
 
//Writes the photo to the server 
 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 
//Tells you if its all ok 
 
echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded successfully, press back to upload more"
 } 
 else { 
 
 
//Gives and error if its not 
 
echo "Sorry, there was a problem uploading your file."
 } 
 
?> 
 <a href="admin-gallery.php"> Back </a>