I'm trying to upload a file. I use to get the fread(): supplied argument is not a valid stream resource error, but then I placed the code in an if statement with file_exists.
The problem is, the if statement never gets executed. - if ($_POST)
-
{
-
include ('scripts/db_connect.php');
-
-
$reviewId = $_POST['review_id'];
-
$form_data = $_POST['form_data'];
-
-
if (file_exists($form_data))
-
{
-
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
-
-
$query = "INSERT INTO uploads (report_id, report_data, report_filename, report_filesize, report_filetype)"
-
. "VALUES (" . $reviewId . ",'" . $data . "','" . $form_data_name . "','" . $form_data_size . "','" . $form_data_type. "')";
-
-
if (mysql_query($query))
-
{
-
// Upload successfull
-
?>
-
<div id="success_box">
-
<div id="success_box_text">The report has been uploaded successfully.</div>
-
</div>
-
<?php
-
}
-
}
-
else
-
{
-
echo "File not found";
-
}
-
-
include ('scripts/db_close.php');
-
}
Anyone know what's going on here?
6 1649
uploaded files are to be found in $_FILES not $_POST. that's why your if statement doesn't get executed.
The file doesn't exist - simple. :P
What does $form_data hold?
Ok I've updated my code, still nothing. - <form action="members.php" method="post" enctype="multipart/form-data">
-
Report Upload:<input type="file" name="form_data" id="form_data" size="30" />
-
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
-
<input type="hidden" name="review_id" value="<?php echo $reviewID; ?>" />
-
<input class="submit" value="Upload" id="submit1" type="submit" style="text-align: center; float: none;"/>
-
</form>
- include ('scripts/db_connect.php');
-
$reviewId = $_POST['review_id'];
-
-
if(isset($_POST[’upload’]) && $_FILES['form_data'][’size’] > 0)
-
{
-
$fileName = $_FILES['form_data'][’name’];
-
$tmpName = $_FILES['form_data'][’tmp_name’];
-
$fileSize = $_FILES['form_data'][’size’];
-
$fileType = $_FILES['form_data'][’type’];
-
$fp = fopen($tmpName, ‘r’);
-
$content = addslashes($content);
-
fclose($fp);
-
-
echo $fileName . "1\n";
-
echo $tmpName . "2\n";
-
echo $fileSize . "3\n";
-
echo $fileType . "4\n";
-
-
if(!get_magic_quotes_gpc())
-
{
-
$fileName = addslashes($fileName);
-
}
-
-
$query = "INSERT INTO report (report_id, report_data, report_filename, report_filesize, report_filetype)"
-
. "VALUES (" . $reviewId . ",'" . $content’ . "','" . $fileName’ . "','" . $fileSize’ . "','" . $fileType’. "')";
-
-
$result = mysql_query($query);
-
-
if (!$result)
-
{
-
echo mysql_error();
-
}
-
}
-
-
include ('scripts/db_close.php');
It doesn't enter the IF statement because $_FILES['form_data'][’size’] is never more than zero. Why doesn't it see the file?
You have no form element with the name 'upload', so the if conditional fails.
Fair enough. I've removed that part of the if statement but it still doesn't pass the
$_FILES['form_data'][’size’] > 0
part. Can anyone recommend me an upload script they actually know works?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ree |
last post by:
I have a tables for a database that I have entried data in to. I have used
the table on my local comp. and used apache & mySql to test it out.
Now I need to upload the table to the site. But...
|
by: Sean Dotson |
last post by:
I have a form that passes variables to an asp file and then uploads a file.
For some reason the request.form is not getting the info from the form.
It's returning blanks. Any insight would be...
|
by: cwho.work |
last post by:
Hi!
We are using apache ibatis with our MySQL 5.0 database (using innodb
tables), in our web application running on Tomcat 5. Recently we
started getting a number of errors relating to...
|
by: =?Utf-8?B?QWRyaWFuIEpvbmVz?= |
last post by:
Hi,
I need to regularly check an FTP folder for the presence of a file, and if
found, run a routine.
Given that this is all on our ISP's servers, what is the best way to
automate such a...
|
by: AHMLIVE |
last post by:
Hi everyone.
I got a problem when i tried to upload MYSQL database. I don't have any idea how to upload it. It is my first time to do it. I already upload the pages from my local pc to server...
|
by: slingare |
last post by:
Hi,
I am new to asp.net and I am having a problem when I try to upload a word document from asp.net to Mysql database. I have a field of type mediumblob in mysql table. I looked for some...
|
by: ELINTPimp |
last post by:
Hello all,
Have a really interesting problem (at least to me) with my
upload_file() function. I have it working now, with a bit of a work
around, but would like to know what everyone thinks in...
|
by: hotflash |
last post by:
Hi All,
I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
|
by: ririe |
last post by:
Hi. I have a problem here. I want to upload a file together with its semester. So I create two field. One for the semester and one for the file to be uploaded. But the script doesn't work. I don't...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |