Noob needs Help!!! HELP please!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nmay
Forum Newbie
Posts: 3
Joined: Wed May 14, 2008 4:05 pm

Noob needs Help!!! HELP please!

Post 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>
";
}
?>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Noob needs Help!!! HELP please!

Post 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
Post Reply