Jump to content

$_FILES wont upload on dir


CiszLaserna

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 :)

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.