I'm trying to upload a pdf file in my Web Host database but it doesn't work .
I have a php file : upload.php
<form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post">
Last name:<br /> <input type="text" name="name" value="" /><br />
class notes:<br /> <input type="file" name="classnotes" value="" /><br />
<input type="submit" name="submit" value="Submit Notes" />
</form>
<?php
define ("filesplace","uploads/"); //uploads is the folder in my server database
if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {
if ($_FILES['classnotes']['type'] != "application/pdf") {
echo "<p>Class notes must be uploaded in PDF format.</p>";
} else {
$name = $_POST['name'];
$result = move_uploaded_file($_FILES['classnotes']['tmp_name'], filesplace."/$name.pdf");
if ($result == 1) echo "<p>Upload done .</p>";
else echo "<p>Sorry, Error happened while uploading . </p>";
}
}
?>
It shows that the file is being uploaded but in the end it shows the error message : Sorry, Error happened while uploading
The file upload.php has all the permissions (777) as well as the uploads folder has.
Im am a free client in 000Webhost , this could be a problem ?
Could you please help me with that situation? :D
Related
Well pretty simple question.. But can't get it right for some reason.
What would be the html code to send a file to this?
move_uploaded_file($FILES["upload"]["tmpname"], $_POST["name"]);
Here's mine but when I used it and echo/vardump everything, I only have 'name' and not the file
<form action="uploader.php" method="post" id="myForm" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="upload" id="upload">
<input type="text" name="name" id="name">
<button name="submit" class="btn btn-primary" type="submit" value="submit">Upload File</button>
</form>
Thank you
i try to add a comment but i can't
first check if upload permission is on in php.ini
file_uploads = On
If it set to on check your upload directory which you added in uploader.php file and use if to check $_FILES['upload'] is empty
this is a simple code to uploader.php file
<?php
if(!empty($_FILES['upload']))
{
$path = "upload/"; /// directory to upload
$path = $path . basename( $_FILES['upload']['name']);
if(move_uploaded_file($_FILES['upload']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['upload']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}else {
echo 'No file selected to upload ';
}
I'm trying to upload an xml file using an Android app I developed.
To do this, I used a free hosting space, and it works great. But now, I want to upload files to one of my pc's folders, using xampp as a web server.
The problem is that when I try to upload files here something goes wrong.
I am sure my php code is good, because it works with the hosting service I have my website on, so I only changed the path, as you can see below.
For hosting service:
<?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
$uploads_dir = '/membri/cendav/gestione_magazzino/ExportData/';
$tmp_name = $_FILES['transactions']['tmp_name'];
$pic_name = $_FILES['transactions']['name'];
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
echo "File not uploaded successfully.";
}
?>
Now, the code for xampp, which is the same:
<?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
$uploads_dir = 'exportdata/';
$tmp_name = $_FILES['transactions']['tmp_name'];
$pic_name = $_FILES['transactions']['name'];
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
echo "File not uploaded successfully.";
}
?>
As you can see, I only changed the $uploads_dir. The path from where I access the file upload.php, from my application http://10.0.0.202:1024/Warepad/.
I also changed the permissions of the exportdata/ folder, to everyone, but it still doesn't work.
P.S. I know there's a ton of these issues, but I still can't find what the problem is.
try this:
<form action="fileupload.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>
So, now it seems to work. It's strange, because the file upload.php is the same, and I haven't changed anything else!
?php
if (is_uploaded_file($_FILES['transactions']['tmp_name'])) {
$uploads_dir = 'exportdata/';
$tmp_name = $_FILES['transactions']['tmp_name'];
$pic_name = $_FILES['transactions']['name'];
move_uploaded_file($tmp_name, $uploads_dir.$pic_name);
}
else{
echo "File not uploaded successfully.";
}
?>
The Android app, now, is able to upload file correctly, but if I try to upload from an html form, it still doesn't work.
Here's the html code:
<html>
<head>
<title>Upload</title>
<meta charset="utf-8">
</head>
<body>
<form action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Invia questo file: <input name="transactions" type="file">
<input type="submit" value="Invia File">
</form>
</body>
</html>
I have a form where multiple images can be selected...
HTML
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="name" class="form-field" placeholder="First Name">
<input type="file" name="files[]" multiple accept="image/*" class="form-field">
<input type="submit" value="UPLOAD" class="button" name="submit4">
</form>
Then, in my PHP I want to detect if at least 1 file has been uploaded.... I tried this, but the code still triggers as if a file was uploaded...
if(isset($_POST['submit4']) and $_SERVER['REQUEST_METHOD'] == "POST")
{
echo "post sucessful<br>";
if(is_uploaded_file($_FILES['files']['temp_name']))
{ echo "file exist";}
else{ echo "no file";}
}
THIS always triggers the "no file" even if there is a file..
and if I try:
if(!empty($_FILES['files']['temp_name']))
it always triggers the "no file" ... I'm really confused...
You can use following code
if(!file_exists($_FILES['files']['tmp_name']) || !is_uploaded_file($_FILES['files']['tmp_name'])) {
echo "No File";
}
else{
echo "Successfully uploaded";
}
Found my answer...
if(!empty($_FILES['files']['name'][0]))
works quit well... thanks everyone.
I have some forms in php that upload data into a mysql database. I have already tested on a localhost server with xampp, but when I upload my files into my host ftp, the forms do not work. I think it has something to do with the fact that I put this file and also the "connect.php" file under password restriction, and that has something to do with the file permissions. I've already granted permission to the user of the database and permission to the file and I also had tried without the password protection, but the result is the same.
So I start to experiment a little and I figured out that the image uploads fine into the database but the other inputs don't, neither the "header" input nor the "article" textarea... knowing that, I tried to "echo out" these input results but none of them show something unless the image input. I came to the conclusion that my form is sending empty data. Can someone make suggestions as to what is happening and how to fix it? Here's my code:
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<div id="slider_upload">
<h1>Slider principal</h1>
<div class="forma">
<form action="sliderPrincipal.php" method="post" enctype="multipart/form-data">
<p><label for="header">Header</label>
<input type="text" id="header" name="header" /></p><br>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<p><label for="fileupload">File to upload</label>
<input type="file" id="fileupload" name="fileupload" /></p><br>
<p><label for="article">article</label>
<textarea id="article" name="article" rows="26" style="width: 100%;" >Write here</textarea></p><br>
<button type="submit" name="submit" value"send">Upload File</button>
</form><br><br>
</div>
</div>
<div class="message">
<?php
$file_dir = "../uploaded";
if (isset($_POST['header'])){
$header = mysql_real_escape_string($_POST['header']);
$article = mysql_real_escape_string($_POST['article']);
}
foreach($_FILES as $file_name => $file_array){
//echo "path: ".$file_array['tmp_name']."<br />\n";
//echo "name: ".$file_array['name']."<br/>\n";
//echo "type: ".$file_array['type']."<br/>\n";
//echo "size: ".$file_array['size']."<br/><br/>\n";
//echo "encabezado ".$encabezado;
if(is_uploaded_file($file_array['tmp_name'])){
move_uploaded_file($file_array['tmp_name'], "$file_dir/".$file_array['name']) or die ("Your image couldnt be uploaded <br>");
$newpath = addslashes("uploaded/".$file_array['name']);
include "connect.php";
$addfile = "INSERT INTO slider (header, image, article) VALUES ('$header','$newpath', '$article')";
$result = mysql_query($addfile);
if ( $result === FALSE ) {
echo "your post could not be uploaded but we already got your image in our files ";
} else{
echo '<p style="padding: 20px;"><h1>Your post was successfully uploaded <h2></p><br><br>';
}
mysql_close();
} else "No file found";
}
?>
</div>
</div>
</body>
</html>
I would like to have the user upload a pdf to a folder on my website. (note:this is for learning purposes, so security is not necessary) The code I have below does not do echo a response when submitted. The folder I would like to have the pdf uploaded to is in the same directory as the php script, is it possible I'm incorrectly referencing that folder? I appreciate it.
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
Email:<br /> <input type = "text" name="email" value=""/><br />
Resume:<br /><input type = "file" name="resume" value=""/><br />
<p><input type="submit" name ="submit" value="Submit Resume" /></p>
</form>
if(isset($_POST['submit']))
{
define ("FILEREPOSITORY","./resume/");
if (is_uploaded_file($_FILES['resume']['tmp_name'])) {
if ($_FILES['resume']['type'] != "application/pdf") {
echo "<p>Resume must be in PDF Format.</p>";
}
}else {
$name = $_POST['email'];
$result = move_uploaded_file($_FILES['resume']['tmp_name'], FILEREPOSITORY."/$name.pdf");
if ($result == 1) {
echo "<p>File successfully uploaded.</p>";
}
else {
echo "<p>There was a problem uploading the file.</p>";
}
}
}
You have a logical error. Your else statement should be part of the inner if statement -- not the outer one.
would suggest you check the permissions for the upload folder and the max size for file uploading in your php.ini... its happened to me many times uploading a file exceeding the limits and not getting an error message.. also the logic of your if else doesn't match as suggested by your previous post..
IT would be of great help to give the error you receive.
move_uploaded_file()
only works if you have the rights to write to the destination folder.