file uploaded successfully but I can't find the file - php

I'm using Azure server to open the website and linking to dropbox to store all the code files. I have an folder called 'image' but after uploading, though it shows "Uploaded!", I can't find that file.
Here's my code:
<?php
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
if (isset($name)){
if(!empty($name)){
$location = 'image/';
if(move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded!';
}else{
echo 'There was an error.';
}
}else{
echo 'Plz choose a file.';
}
}
?>
<form action="add.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="file" id="file">
<input type="submit" value="Upload Image" name="submit">
</form>

Your uploaded file is in the image folder that is in the same folder of your page.php.
See your code:
$location = 'image/';
if(move_uploaded_file($tmp_name, $location.$name)){
The final location of your file is $location.$name. This is image/your_file_name.your_extension

Related

i think move uploaded file is not working even though he can find if the file is existed

If i choose in the same folder of my target directory it said file exist but when i choose in different folder it said success but there`s no file uploaded in that folder here is my code. i get it in google
<?php
if (($_FILES['my_file']['name']!="")){
// Where the file is going to be stored
$target_dir = "/home/cidinc1802/Pictures/";
$file = $_FILES['my_file']['name'];
$path = pathinfo($file);
$filename = $path['filename'];
$ext = $path['extension'];
$temp_name = $_FILES['my_file']['tmp_name'];
$path_filename_ext = $target_dir.$filename.".".$ext;
if (file_exists($path_filename_ext)) {
echo "Sorry, file already exists.";
}else{
move_uploaded_file($temp_name,$path_filename_ext);
echo "Congratulations! File Uploaded Successfully.";
}
}
?>
<form name="form" method="post" action="fortesting.php" enctype="multipart/form-data" >
<input type="file" name="my_file" /><br /><br />
<input type="submit" name="submit" value="Upload"/>
</form>

move_upload_file() is not working

<?php
if (isset($_FILES['file']['name'])){
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$location = 'uploads/';
if (!empty($name)){
if(move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded successful';
}
}else
echo 'Please select a file.';
}?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
I am not getting any error but the move_uploaded_file() is not working. It displayed no result on the browser. I have the folder 'uploads/' inside my directory.
The problem is solved, the maximum file size for the file to be uploaded is 2MB. The file that I tried to upload exceed 0.1MB. Thank all of you.

How to upload to a different drive in PHP?

I have a php page that lets you upload files, and the files just get uploaded to my computer, but I need them to be uploaded to a different hard drive. I need them to be uploaded to
"D:\uploads". I know there are some other problems with this code but i just need this out of the way. Heres the code itself:
<link rel="icon" type="image/png" href="favicon.ico.ico"/>
<?php
define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT']."/");
define("PDF_UPLOADS", DOC_ROOT."uploads/");
#$name = $_FILES['file']['name'];
#$size = $_FILES['file']['size'];
#$type = $_FILES['file']['type'];
#$tmp_name = $_FILES['file']['tmp_name'];
if (isset($name))
{
if (!empty($name))
{
if(move_uploaded_file($tmp_name, PDF_UPLOADS. $name))
echo 'Uploaded';
else
echo "Not Uploaded";
}
else
{
echo 'Please choose a file';
}
}
?>
<form action="first.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="Submit" value="Submit">
</form>
Wouldn't it be as simple as this:
define("PDF_UPLOADS", "D:/uploads/");

How to upload image in a specific folder php?

I have xampp installed and I have a program that you choose a file and it gets uploaded to my server. I have a folder in htdocs called uploads thats meant for storing the pictures. When I upload them, it goes in the htdocs, but not the folder in htdocs i want. I did specify that i needed it to go there. Can someone help?
Heres the code:
<?php
#$name = $_FILES['file']['name'];
#$size = $_FILES['file']['size'];
#$type = $_FILES['file']['type'];
#$tmp_name = $_FILES['file']['tmp_name'];
if (isset($name)) {
if (!empty($name))
{
$location = 'uploads/';
if (move_uploaded_file($tmp_name, $location. $name));
echo 'Uploaded';
}
else
{
echo 'Please choose a file';
}
}
?>
<form action="first.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="Submit" value="Submit">
</form>
Try below code:
Note: Make sure your uploads folder have write permission.
<?php
define("DOC_ROOT", $_SERVER['DOCUMENT_ROOT']."/");
define("PDF_UPLOADS", DOC_ROOT."uploads/");
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
if (isset($name))
{
if (!empty($name))
{
if(move_uploaded_file($tmp_name, PDF_UPLOADS. $name))
echo 'Uploaded';
else
echo "Not Uploaded";
}
else
{
echo 'Please choose a file';
}
}
?>

PHP trying to move file with move_uploaded_file

I have been back forward about this, can't find a solution. My file that I am trying to upload is not moving. I'm using WAMP and my root folder is C:\wamp\www
I've checked that the directory exists in php and put in a script that if it does not exist it should be created, which works, but still it is not moving the file. What am I doing wrong?
The Form:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
Upload.php
$target_path = "uploads/" ;
if(!file_exists($target_path)) {
mkdir($target_path, 0755, true);
echo "The directory was created";
}
$tmp_name = $_FILES['file']['tmp_name'];
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
echo $target_path;
if(move_uploaded_file($tmp_name, $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
try to change,
$tmp_name = $_FILES['file']['tmp_name'];
to
$tmp_name = $_FILES['uploadedfile']['tmp_name'];

Categories