473,836 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to upload file to MySQL, file not found

30 New Member
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');
  5.         $reviewId = $_POST['review_id'];
  6.         $form_data = $_POST['form_data'];
  8.         if (file_exists($form_data))
  9.         {
  10.             $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
  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. "')";
  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.         }
  30.         include ('scripts/db_close.php');
  31.     }
Anyone know what's going on here?
Mar 19 '09 #1
6 1663
8,658 Recognized Expert Moderator Expert
uploaded files are to be found in $_FILES not $_POST. that's why your if statement doesn't get executed.
Mar 19 '09 #2
6,050 Recognized Expert Expert
The file doesn't exist - simple. :P

What does $form_data hold?
Mar 19 '09 #3
30 New Member
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'];
  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);
  14.             echo $fileName . "1\n";
  15.             echo $tmpName . "2\n";
  16.             echo $fileSize . "3\n";
  17.             echo $fileType . "4\n";
  19.             if(!get_magic_quotes_gpc())
  20.             {
  21.                 $fileName = addslashes($fileName);
  22.             }
  24.             $query = "INSERT INTO report (report_id, report_data, report_filename, report_filesize, report_filetype)"
  25.                                 . "VALUES (" . $reviewId . ",'" . $content’ . "','" . $fileName’ . "','" . $fileSize’ . "','" . $fileType’. "')";
  27.             $result = mysql_query($query);
  29.             if (!$result) 
  30.             {
  31.                 echo mysql_error();
  32.             }
  33.         }
  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
6,050 Recognized Expert Expert
You have no form element with the name 'upload', so the if conditional fails.
Mar 19 '09 #5
30 New Member
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
6,050 Recognized Expert Expert
Mar 19 '09 #7

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 not sure how to do it. I don't want to enter the details all again. Can someone point me to a link that explains how to upload these tables. Also the the webhost is using Cpanel.
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 appreciated.... Here is the asp file <HTML> <HEAD> <TITLE>File Upload Results</TITLE>
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 java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"; We get such errors generally on inserts or updates while applying a
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 routine in ASP.NET? The end target of the routine is likely to be a MySQL database. If we were using SQL Server, I assume I could use DTS to trigger the process, but I'm
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 with Bulletproof FTP transfer and now I want to upload my database. For now I am using vertrigoServ 2.15 and I found my database in folder path C:\Program Files\VertrigoServ2\Mysql\data\mydatabase. and i want it to transfer to my server. Do I need...
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 example online but found a few that use Access database or SQL databse. but they didnot help me in solving the problem. I need to be able to upload the file and save it to the mysql database and then I should also be able to view the file that was...
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 regards to this being a bug or perhaps my ignorance. Basically the function takes two arguments, one is the desired file path I want the upload file to be moved to, and the second is an arbitrary integer. If the file doesn't already exist, the...
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 don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before...
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 know why. However, if I try to upload the file without the semester field, the script is working. May be the problem comes from the semester field. This is my codes. Form.php ?><?php require_once('Connections/connection.php'); ?><?php if...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.