Page 1 of 1

Noob needs Help!!! HELP please!

Posted: Wed May 14, 2008 4:12 pm
by nmay
I am writing a simple script to upload files to database. When I upload a file, the temp file name is
C:\tempuploads\phpA.tmp but nothing is in my tempuploads folder and therefore my $fp is NULL.
Can somebody point out what I did wrong? I do have full permission on tempuploads, why are there no files
in that folder?

$tmpName1 is C:\tempuploads\phpA.tmp
fp is null
content is null


<?php
$user =& JFactory::getUser();
$userid = $user->get('id');

if(isset($_POST['upload']) && $_FILES['result']['size'] > 0)
{
$fileName1 = $_FILES['result']['name'];
$tmpName1 = $_FILES['result']['tmp_name'];
$fileSize1 = $_FILES['result']['size'];
$fileType1 = $_FILES['result']['type'];
}

echo $tmpName1;

$fp = fopen($tmpName1, 'r');

if ($fp == null) echo "fp is null";

$content1 = fread($fp, filesize($tmpName1));

echo $content1;

if ($content1 == null) echo "content is null";

$content1 = addslashes($content1);
fclose($fp);
if(!get_magic_quotes_gpc())
{ $fileName1 = addslashes($fileName1);
}

$database =& JFactory::getDBO();

$testquery = "INSERT INTO jos_uploads (userid, name, type, size, content) VALUES ('$userid', '$fileName1', '$fileType1', '$fileSize1', '$content1')";

$database->setQuery($testquery);

if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>

Re: Noob needs Help!!! HELP please!

Posted: Wed May 14, 2008 6:03 pm
by califdon
When posting code in a forum like this, please help us by enclosing your code in code tags:
[syntax=php]. . .[/syntax]
You can use the "Code" button at the top of the message entry space.
Also, please DO NOT use vague Subjects like "Noob needs Help!!! HELP please!" That will turn away a large percentage of people who might otherwise be willing to help you. We respond to specific descriptions of what your question is about. In this case, it could be something like "File Uploading problem."

Now, it appears that you are trying to assign a value to the temp filename. As far as I know, you can't do that. The system assigns the name to the file, which you then retrieve from the $_FILES array and use when you move it to where you want it.

Read these:
http://www.tizag.com/phpT/fileupload.php
http://us3.php.net/features.file-upload