473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying to upload file to MySQL, file not found

30
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.

Expand|Select|Wrap|Line Numbers
  1. if ($_POST)
  2.     {
  3.         include ('scripts/db_connect.php');
  4.  
  5.         $reviewId = $_POST['review_id'];
  6.         $form_data = $_POST['form_data'];
  7.  
  8.         if (file_exists($form_data))
  9.         {
  10.             $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
  11.  
  12.             $query = "INSERT INTO uploads (report_id, report_data, report_filename, report_filesize, report_filetype)"
  13.                         . "VALUES (" . $reviewId . ",'" . $data . "','" . $form_data_name . "','" . $form_data_size . "','" . $form_data_type. "')";
  14.  
  15.             if (mysql_query($query))
  16.             {
  17.                 // Upload successfull
  18.                 ?>
  19.                 <div id="success_box">
  20.                     <div id="success_box_text">The report has been uploaded successfully.</div>
  21.                 </div>
  22.                 <?php
  23.             }
  24.         }
  25.         else
  26.         {
  27.             echo "File not found";
  28.         }
  29.  
  30.         include ('scripts/db_close.php');
  31.     }
Anyone know what's going on here?
Mar 19 '09 #1
6 1649
Dormilich
8,658 Expert Mod 8TB
uploaded files are to be found in $_FILES not $_POST. that's why your if statement doesn't get executed.
Mar 19 '09 #2
Markus
6,050 Expert 4TB
The file doesn't exist - simple. :P

What does $form_data hold?
Mar 19 '09 #3
mlevit
30
Ok I've updated my code, still nothing.

Expand|Select|Wrap|Line Numbers
  1. <form action="members.php" method="post" enctype="multipart/form-data">
  2.                                         Report Upload:<input type="file" name="form_data" id="form_data" size="30" />
  3.                                         <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> 
  4.                                         <input type="hidden" name="review_id" value="<?php echo $reviewID; ?>" />
  5.                                         <input class="submit" value="Upload" id="submit1" type="submit" style="text-align: center; float: none;"/>
  6.                                     </form>
Expand|Select|Wrap|Line Numbers
  1. include ('scripts/db_connect.php');
  2.         $reviewId = $_POST['review_id'];
  3.  
  4.         if(isset($_POST[’upload’]) && $_FILES['form_data'][’size’] > 0)
  5.         {
  6.             $fileName = $_FILES['form_data'][’name’];
  7.             $tmpName = $_FILES['form_data'][’tmp_name’];
  8.             $fileSize = $_FILES['form_data'][’size’];
  9.             $fileType = $_FILES['form_data'][’type’];
  10.             $fp = fopen($tmpName, ‘r’);
  11.             $content = addslashes($content);
  12.             fclose($fp);
  13.  
  14.             echo $fileName . "1\n";
  15.             echo $tmpName . "2\n";
  16.             echo $fileSize . "3\n";
  17.             echo $fileType . "4\n";
  18.  
  19.             if(!get_magic_quotes_gpc())
  20.             {
  21.                 $fileName = addslashes($fileName);
  22.             }
  23.  
  24.             $query = "INSERT INTO report (report_id, report_data, report_filename, report_filesize, report_filetype)"
  25.                                 . "VALUES (" . $reviewId . ",'" . $content’ . "','" . $fileName’ . "','" . $fileSize’ . "','" . $fileType’. "')";
  26.  
  27.             $result = mysql_query($query);
  28.  
  29.             if (!$result) 
  30.             {
  31.                 echo mysql_error();
  32.             }
  33.         }
  34.  
  35.         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?
Mar 19 '09 #4
Markus
6,050 Expert 4TB
You have no form element with the name 'upload', so the if conditional fails.
Mar 19 '09 #5
mlevit
30
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?
Mar 19 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
2
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...
0
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...
6
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...
3
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...
0
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...
2
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...
2
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...
1
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.