Jump to content

upload not working???


Recommended Posts

Hi,

 

I have a problem... I am trying to upload an image to my sql database the file name is generated by the datetime stamp and it should be uploaded to a folder named files. For some reason my file name gets put into my database but it is missing the extension. And the file never uploads ???. I feel like I’ve been looking at it or hours and it is getting me so I figured I’d ask you for help.

 

Thanks in advance,

Jason

 

Here is the code

<?php

 

include "config.php";

 

// Your file name you are uploading

$file_name = $HTTP_POST_FILES['ufile']['name'];

 

// random 4 digit to add to our file name

// some people use date and time in stead of random digit

//$random_digit=rand(0000,9999);

$random_digit=uniqid("file_");

 

//combine random digit to you file name to create new file name

//use dot (.) to combile these two variables

 

$new_file_name=$random_digit.$file_name;

 

//set where you want to store files

//in this example we keep file in folder upload

//$new_file_name = new upload file name

//for example upload file name cartoon.gif . $path will be upload/cartoon.gif

$path= "file/".$new_file_name;

 

$tbl_name="forum_question";

 

$topic=$_POST['topic'];

$detail=$_POST['detail'];

$name=$_POST['name'];

$email=$_POST['email'];

$file=$_POST['new_file_name'];

$file_type=$_POST['file_type'];

$username=$_POST['username'];

 

$datetime=date("d/m/y h:i:s"); //create date time

 

 

$sql="INSERT INTO $tbl_name(username, topic, detail, name, email, file, file_type, datetime)VALUES('$username', '$topic', '$detail', '$name', '$email', '$new_file_name', '$file_type', '$datetime')";

 

 

$result = mysql_query($sql) or die (mysql_error());

 

//if($result)

//{

 

if($ufile !=none)

{

if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))

{

echo "Successful<BR/>";

 

//$new_file_name = new file name

//$HTTP_POST_FILES['ufile']['size'] = file size

//$HTTP_POST_FILES['ufile']['type'] = type of file

echo "File Name :".$new_file_name."<BR/>";

echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";

echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";

}

else

{

echo "Error";

}

}

?>

 

Here is the file that I got the upload code from and it works fine.

 

<?

session_start();

if (empty($_SESSION['username'])){

header("location:login.php");

exit;

}

 

?>

 

<?php

 

include "config.php";

 

// Your file name you are uploading

$file_name = $HTTP_POST_FILES['ufile']['name'];

 

// random 4 digit to add to our file name

// some people use date and time in stead of random digit

$random_digit=uniqid("file_");

 

 

//combine random digit to you file name to create new file name

//use dot (.) to combile these two variables

 

$new_file_name=$random_digit.$file_name;

 

//set where you want to store files

//in this example we keep file in folder upload

//$new_file_name = new upload file name

//for example upload file name cartoon.gif . $path will be upload/cartoon.gif

$path= "file/".$new_file_name;

 

$query= "INSERT INTO forum_question (file) VALUES ('$new_file_name')";

mysql_query($query);

 

echo $query;

echo "Record updated <br / >";

 

 

if($ufile !=none)

{

if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))

{

echo "Successful<BR/>";

 

//$new_file_name = new file name

//$HTTP_POST_FILES['ufile']['size'] = file size

//$HTTP_POST_FILES['ufile']['type'] = type of file

echo "File Name :".$new_file_name."<BR/>";

echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";

echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";

}

else

{

echo "Error";

}

}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/104466-upload-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.