Jump to content

Recommended Posts

here is my upload_file.php

 

<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));


if ($_FILES["file"]["size"] < 20000)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";


if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
INSERT INTO reports (Stations,Title,Detail,Attach) VALUES('$_POST[stations]','$_POST[title]','$_POST[detail]','$_FILES[file]')";
}
}
}
else
{
echo "Invalid file";
}
?>

 

 

and here is my insert code for the result because a wanted to try if i can download the file i upload from the db itself

 

<?php
$con=mysql_connect("localhost","root","");


mysql_select_db("report");
$sql="INSERT INTO reports (Stations,Title,Detail,Attach) VALUES('$_POST[stations]','$_POST[title]','$_POST[detail]','$_FILES[file]')";
$sql_res = mysql_query($sql);


header("Location: report.php?ok=1");
mysql_close($con);
?>

 

form code html

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

 

im kinda new at php :)

Edited by CiszLaserna
Link to comment
https://forums.phpfreaks.com/topic/274261-_files-wont-upload-on-dir/
Share on other sites

Also what is this doing in the else { } in the first lot of code?

INSERT INTO reports (Stations,Title,Detail,Attach) VALUES('$_POST[stations]','$_POST[title]','$_POST[detail]','$_FILES[file]')";

 

You already have that in the mysql_query in the second file

Cisz, you have failed to even mention the exact problem you are having. You pretty much just regurgitated your code out to us and said "It doesn't work." As you can see by the number of replies you surprisingly have already, this community wants to help you, but they cannot do so effectively if you do not ask your question effectively.

 

Are you positive that your file uploaded correctly? If you are not sure, then check through FTP or whatever means you use to view your files.... if it is there, then you're problem may be that you are giving the wrong path. We need to know things like, your directory structure and whether or not the upload actually works....etcetera... details.

Edited by Zane
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.