PHP Upload Wont Work, But Wordpress Upload Does - php

I am creating my own upload script to upload files to my webserver (like small flash videos). However, it does not seem to be working. However, I don't think it is PHP because uploading files to my server via Wordpress does work.
Here is the upload form:
<form enctype="multipart/form-data" action="upload.php" method="POST">
Video: <input name="vid" type="file" />
<br/>
Name: <input name="title" type="text" />
<br/>
Description:
<br/>
<br/>
<textarea name="desc">Your description here</textarea>
<br/>
<br/>
<input type="submit" value="Upload" />
</form>
Here is the upload PHP page:
<?php
$target = basename( $_FILES['uploaded']['name']) ;
$ok=1;
//check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
I have set the max upload size in php.ini to 100MB, however, the upload still fails. My php.ini file can be viewed here at pastebin. Also note that I have removed all verification from the upload script to see if it works.

From the looks of your code, you are uploading the file in the same directory as the running script. Are you sure you have write permission for the webserver in that directory?
Try uploading the file in your temp directory:
move_uploaded_file($_FILES['uploaded']['tmp_name'], sys_get_temp_dir().DIRECTORY_SEPARATOR.$target);
and see if it works
UPDATE
You are calling your input file "vid" but you are trying to access the input "uploaded".
replace all your $_FILES occurences with $_FILES['vid'][]...
And enable error reporting on your machine

How could you get the value of video from this:
$target = basename( $_FILES['uploaded']['name']) ;
WHile the 1st block contain the name of the file which was given to the html.
IN your case it is : Video: <input name="vid" type="file" /> Vid
SO use this on your code:
<?php
$target = basename( $_FILES['vid']['name']) ;

Related

PHP file upload not working - tried lots of tutorial websites, permissions correct, php.ini correct

I am hosting a file upload script on an digital ocean server. I have copied line for line tutorials from all over the internet and changed my permissions using CHMOD 777. I cannot for the life of me figure out why the file won't upload.
PHP
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['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!";
}
?>
HTML
<form enctype="multipart/form-data" action="upload_manager.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
The file I'm trying to upload is only a few hundred KB and is a PNG. I have tried JPEG too.
When I print out the value of
$_FILES['uploadedfile']['tmp_name']
It is empty
The value of
$_FILES['uploadedfile']['name']
is the file name.
I had a look at my php ini and everything related to uploading files is correct.
What else can I try to get this to work?

Form doesn't see file uploader - php

I'm attempting to build my first form/file uploader (I'm a newb fyi).
I am testing on a local server on my mac, both the form, file handler, and the uploads folder are in the same file directory with one another.
When I select a file using the submit form (test file is 'testFilego.txt' and 3 bytes in size'), i get the following error: http://localhost/PhP_exercises/__tizag/280-php-fileupload-test.php?MAX_FILE_SIZE=2500000&uploadedfile=testFilego.txt. The submit form doesn't seem to connect to the handler (?). I thought the test file would appear in my uploads folder. Help.
This is the submit form:
<form>
<form enctype="multipart/form-data" action="280-php-uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="2500000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</form>
This is the file hander the form ought to be contacting
<?php
280-php-uploader.php&lt?php
//This is '280-php-uploader.php'
// Where the file is going to be placed
$target_path = "uploads/";
// Add the original filename to our target path.
//Result is "uploads/filename.extension"
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['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!";
}
?>
As Marco Acierno observed, i'd posted the form inside a form and that seems to have caused the problem.

uploading videos into a folder and its link to database using PHP/MySQL

I am trying to upload a video and save it in a folder as well as savings its path in the database, but the videos are not inserting into the specific folder.
I have searched a lot and found some code. The code is working for images. I have done some modifications from images to videos, but that didn't work.
Here is the parts of my code.
<form action="" method="post" enctype="multipart/form-data">
<div class="form_search">
<label>Upload Video Profile:</label>
<span class="form_input">
<input type="file" name="uploadvideo" />
</span>
</div>
<div class="form_search">
<label> </label>
<span class="form_input">
<input type="submit" name="submitdetails" value="Upload" class="button"/>
</span>
</div>
</form>
and my php code to upload video is
<?php
if(isset($_POST['submitdetails']))
{
$name=$_FILES['uploadvideo']['name'];
$type=$_FILES['uploadvideo']['type'];
//$size=$_FILES['uploadvideo']['size'];
$cname=str_replace(" ","_",$name);
$tmp_name=$_FILES['uploadvideo']['tmp_name'];
$target_path="company_profile/";
$target_path=$target_path.basename($cname);
if(move_uploaded_file($_FILES['uploadvideo']['tmp_name'],$target_path))
{
echo "hi";
echo $sql="UPDATE employer_logindetails SET (video) VALUES('".$cname."')";
$result=mysql_query($sql);
echo "Your video ".$cname." has been successfully uploaded";
}
}
?>
Please help me where I am going wrong.
All my php.ini modifications are done, and video size is only 7mb.
Step-1
This script will allow you to upload files from your browser to your hosting, using PHP. The first thing we need to do is create an HTML form that allows people to choose the file they want to upload.
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
This form sends data to the file "upload.php", which is what we will be creating next to actually upload the file.
Step-2
The actual file upload is very simple:
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
This very small piece of code will upload files sent to it by your HTML form.
The first line $target = "upload/"; is where we assign the folder that files will be uploaded to. As you can see in the second line, this folder is relative to the upload.php file. So for example, if your file was at www.yours.com/files/upload.php then it would
upload files to www.yours.com/files/upload/yourfile.gif. Be sure you remember to create
this folder! with 777 rights
Step-3
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
Assuming that you didn't change the form field in our HTML form (so it is still named uploaded), this will check to see the size of the file. If the file is larger than 350k, they are given a file too large error, and we set $ok to equal 0.
You can change this line to be a larger or smaller size if you wish by changing 350000 to a different number. Or if you don't care about file size, just leave these lines out
We are not using $ok=1; at the moment but we will later in the tutorial.
We then move the uploaded file to where it belongs using move_uploaded_file (). This places it in the directory we specified at the beginning of our script. If this fails the user is given an error message, otherwise they are told that the file has been uploaded.
Putting All Together
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
Obviously if you are allowing file uploads you are leaving yourself open to people uploading lots of undesirable things. One precaution is not allowing them to upload any php, html, cgi, etc. files that could contain malicious code. This provides more safety but is not sure fire protection.
Try this: $_FILES['userfile'] in place of $_FILES['uploadvideo'] everywhere.
I don'e see any name with uploadvideo in your form.
But in php you are using $_FILES['uploadvideo']
Try giving the exact name of the file input
e.g.:
<input type="file" name="uploadvideo">

Basic PHP Upload script with no result

I have a very simple upload script. Here is my HTML file that allows a user to submit a file:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
And then here is my PHP file that actually places the file on my server
<?php
echo "starting the upload initially";
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
I have the html saved at url.com/uploading.html and the php saved at url.com/uploader.php
After loading the HTML page and putting a file in the uploader the browser redirects me to the php file but then doesn't do anything further, not even print out that initial statement that I have. Do you see any problems? All of the permissions are 777 so that shouldn't be it. Could there be any other things I need to take care of on my server? Everything is in the same folder too.
Thanks!
Could you verify that post_max_size and upload_max_filesize is greater than or equal to the size of the file you're attempting to upload?
Is it possible your max size is > than the size of your file

trying to upload file to server, but php script not getting file details

I am trying to upload an image to a server, then get that image name and insert it into mysql database. Before I got to the database bit, the upload isn't working. I have narrowed it down to the fact there is no data in the $_FILES array, when I echo out $imageFileName is it blank.
Here is part of my form:
<form name="addItem" method="post" action="add-new-item.php">
<input name="name" placeholder="Portfolio Item Name" type="text" id="itemName"/><br />
<input type="file" name="imageName" id="imageName" /><br />
</form>
Script, which is part of the same page the form is on:
$target = "images/";
$target = $target . basename( $_FILES['imageName']['name']);
$imageFileName=($_FILES['imageName']['name']);
if(move_uploaded_file($_FILES['imageName']['tmp_name'], $target)){
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}else {
echo "Sorry, there was a problem uploading your file.";
}
$query1="INSERT INTO portfolio_items (item_name,full_size_image) VALUES('$itemName','$itemImage')";
You need to include the following in your <form> tag :
enctype="multipart/form-data"
So it would become :
<form name="addItem" method="post" action="add-new-item.php" enctype="multipart/form-data">
Documented very well here - see the note at the bottom of the first page ...

Categories