metal Posted May 2, 2007 Share Posted May 2, 2007 I am currently building a website as a project. The web site needs to upload files to a database. I am using blobs to create my code. The code enters all the information about the file eg, name, file type, etc but it does not physically upload the file. The code I have entered is displayed below. I would assistance if anyone could shed a light on what I am doing wrong :-\ <?php include("connection.php"); $connection = connect(); $strDesc = $_POST['strDesc']; $fileUpload = $_POST['fileUpload']; $fileUpload_name = $_FILES['fileUpload'] ['name']; $fileUpload_size = $_FILES['fileUpload'] ['size']; $fileUpload_type = $_FILES['fileUpload'] ['type'];; // Make sure both a description and // file have been entered if(empty($strDesc) || $fileUpload == "none") die("You must enter both a description and file"); fopen($fileUpload, "r"); //$file_contents = fread($fp, filesize($postfile)); $file_contents = file_get_contents($fileUpload); //fclose($fp); $dbQuery = "INSERT INTO myBlobs VALUES "; $dbQuery .= "(0, '$strDesc', '$file_contents', '$fileUpload_type')"; mysql_query($dbQuery) or die("Couldn't add file to database"); echo "<h1>File Uploaded</h1>"; echo "The details of the uploaded file are shown below:<br><br>"; echo "<b>File name:</b> $fileUpload_name <br>"; echo "<b>File type:</b> $fileUpload_type <br>"; echo "<b>File size:</b> $fileUpload_size <br>"; echo "<a href='getfiles.php'>Add Another File</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/49656-problems-with-file-upload/ Share on other sites More sharing options...
arianhojat Posted May 2, 2007 Share Posted May 2, 2007 For this line,... $file_contents = file_get_contents($fileUpload); .... Reading the php manual, i think u need to supply the filename itself to file_get_contents not the POST info. echo 'Folder temporarily uploaded to(make sure this path correct) ='. $_FILES['userfile']['tmp_name'][0]; $file_contents = file_get_contents($_FILES['userfile']['tmp_name'][0]); //maybe delete file when done unlink($_FILES['userfile']['tmp_name'][0]) ; Link to comment https://forums.phpfreaks.com/topic/49656-problems-with-file-upload/#findComment-243606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.