The error is Warning: move_uploaded_file(uploads/cv/23456543555555CURRICULUM VITAE.doc): failed to open stream: No such file or directory in C:\wamp\www\job-application\include\application.class.php on line 121
Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php7EA1.tmp' to 'uploads/cv/23456543555555CURRICULUM VITAE.doc' in C:\wamp\www\job-application\include\application.class.php on line 121
The code follows below;
$allowedExtsDoc = array("docx", "pdf", "doc");
$temp = explode(".", $_FILES["file"]["name"]);
$extensionDoc = end($temp);
$uploaddircv = 'uploads/cv/';
$uploadfilecv = $uploaddircv . basename($phone.$_FILES['file']['name']);
if (in_array($extensionDoc, $allowedExtsDoc))
{
if ($_FILES["file"]["error"] > 0)
{
$this->error .= $_FILES["file"]["error"] . "<br>";
}
else
{
if (file_exists($uploaddircv . $_FILES["file"]["name"]))
{
$this->error .= $_FILES["file"]["name"] . " already exists. <br/>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],$uploadfilecv);
$fileloc = $this->sitePath.$uploadfilecv;
}
}
}
else
{
$this->error .= "Invalid file <br/>";
}
Make sure the directories: C:\wamp\tmp\ and uploads/cv/ exists and are writable by Apache.
After that, try to use the complete path to uploads folder.
$uploaddircv = realpath(dirname(__FILE__) . '/../uploads/cv/') . '/';
Related
In this php code I want to customize the image upload destination. with this php file, I have directory called uploads. I want to add all my uploaded images to this directory and store path in db. how can I do this?
<?php
// Assigning value about your server to variables for database connection
$hostname_connect= "localhost";
$database_connect= "image_upload";
$username_connect= "root";
$password_connect= "";
$connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
#mysql_select_db($database_connect) or die (mysql_error());
if($_POST) {
// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.
if ($_FILES["file"]["error"] > 0) {
// if there is error in file uploading
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
// check if file already exit in "images" folder.
if (file_exists("images/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
//move_uploaded_file function will upload your image. if you want to resize image before uploading see this link http://b2atutorials.blogspot.com/2013/06/how-to-upload-and-resize-image-for.html
if(move_uploaded_file($_FILES["file"]["tmp_name"],"images/" . $_FILES["file"]["name"])) {
// If file has uploaded successfully, store its name in data base
$query_image = "insert into acc_images (image, status, acc_id) values ('".$_FILES['file']['name']."', 'display','')";
if(mysql_query($query_image)) {
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
} else {
echo 'File name not stored in database';
}
}
}
}
}
?>
currently when I run the upload
I am getting warnings
Warning: move_uploaded_file(images/1409261668002.png): failed to open stream: No such file or directory in D:\xampp\htdocs\image-upload\index.php on line 29
Warning: move_uploaded_file(): Unable to move 'D:\xampp\tmp\php1C1F.tmp' to 'images/1409261668002.png' in D:\xampp\htdocs\image-upload\index.php on line 29
You must specify a correct path, the 'images/1409261668002.png' path doesn't exist if you dont create them and don't specify them.
if(move_uploaded_file($_FILES["file"]["tmp_name"],"images/" . $_FILES["file"]["name"]))) { .... }
You must specify the absolute path
You can use below code:
$image=basename($_FILES['file']['name']);
$image=str_replace(' ','|',$image);
$tmppath="images/".$image;
if(move_uploaded_file($_FILES['file']['tmp_name'],$tmppath))
{...}
Let me know if you have any query/concern regarding this.
I have PHP code like this:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
$error = array();
if (isset($_POST['submit'])) {
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'upload';
if (!empty($_FILES)) {
$tmp = $_FILES['file']['tmp_name'];
$file = $dir . DIRECTORY_SEPARATOR . $_FILES['file']['name'];
if (is_uploaded_file($tmp)) {
if (!chown($dir, 'nobody')) {
$error[] = 'Owner tidak bisa di replace!';
}
if (!chmod($dir, intval(755, 8))) {
$error[] = 'Direktori "' . $dir . '" tidak bisa diberi akses!';
}
if (!move_uploaded_file($tmp, $file)) {
$error[] = 'Gagal memindahkan berkas "' . $file . '"';
}
if (file_exists($file)) {
$error[] = 'Berhasil di unggah! ' . $file;
}
} else {
$error[] = 'Berkas tidak bisa di unggah.';
}
}
}
?>
When running this code the following messages appear:
Warning: chown(): Operation not permitted in /var/www/html/jdih/upload.php on line 23
Warning: chmod(): Operation not permitted in /var/www/html/jdih/upload.php on line 24
Warning: move_uploaded_file(/var/www/html/jdih/upload/06-naiveBayes-example.pdf): failed to open stream: Permission denied in /var/www/html/jdih/upload.php on line 25
Warning: move_uploaded_file(): Unable to move '/tmp/phpMHL5CQ' to '/var/www/html/jdih/upload/06-naiveBayes-example.pdf' in /var/www/html/jdih/upload.php on line 25
What's going on here?
You should verify file permissions and file owner.
To change file permissions :
chmod -R 775 /var/www/html/jdih
And set the owner to the user who run your apache server.
chown www-data:www-data /var/www/html/jdih
Note : the owner depends on your distribution, on Ubuntu it's www-data, it could be httpd or http or something else.
Go to terminal, and type:
chmod -R 775 /your/upload/folder/path
then you set the permission to write in this dir
I have included an upload script, which currently ONLY checks the upload folder to make sure that the file isn't there, which works just fine. However, I would like to somehow silently include a search function to see if it is already in one of the other directories.
The process: User uploads a prl, it checks upload folder if its there. This works. I need it to check another directory (recursively) to see if it is in any subdirectory already, and then list them out.
Just a note: $carrier is an existing subdirectory. I would like it to check the parent directory and all of its subs for the filename minus the extension, and if it exists, Error: this file already exists for "this" carrier.
<?php
$allowedExts = array("prl");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$carrier = $_POST['carrier'];
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
if (file_exists("./prls/" . $carrier . "/" . $_FILES["file"]["name"])){
echo "<h2><u>Error:</u></h2>";
echo $_FILES["file"]["name"] . " is already listed in the " . $carrier . " directory. ";
echo "<hr><br />If you feel this PRL is listed incorrectly, please let us know.";
die;
}
if (file_exists("upload/" . $_FILES["file"]["name"] . "-" .$carrier)) {
echo "<h2><u>Error:</u></h2>";
echo $_FILES["file"]["name"] . " for <b>" . $carrier . "</b> has already beeb submitted for approval. ";
die;
}
if ($_FILES["file"]["error"] == 0 && in_array($extension, $allowedExts))
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"] . "-" . $carrier);
echo "<h2><u>Submitted for approval:</u></h2>";
echo $_FILES["file"]["name"] . " for " . $carrier . ". <b>Thank you</b>.";
}
else
{
echo "Invalid file. Please choose a PRL with a \".prl\" extension.";
}
?>
You want to use RecursiveIteratorIterator. Here's a function that will behave like file_exists():
function file_exists_recursive($dir, $filename) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST );
foreach($iterator as $path) {
if (!$path->isDir()) {
if(file_exists($filename.$path->__toString()))
return true;
}
return false;
}
}
Then call this function in your file:
if (file_exists_recursive("upload/", $_FILES["file"]["name"] . "-" .$carrier)) {
echo "<h2><u>Error:</u></h2>";
echo $_FILES["file"]["name"] . " for <b>" . $carrier . "</b> has already beeb submitted for approval. ";
die;
}
Hi I am attempting to create a new zip file, I have recompiled PHP enabling ZIP and here is my code
if($_SERVER['REQUEST_METHOD'] == "POST"){
$zip = new ZipArchive;
if($zip->open("/home/user1joe/public_html/upload/test.zip",ZIPARCHIVE::CREATE)!= true) {
echo "error file did not up upload";
exit(0);
}
foreach ($_FILES["images"]["error"] as $key => $error)
if ($error == UPLOAD_ERR_OK) {
$temp_name = $_FILES["images"]["tmp_name"][$key];
$new_name = $_FILES['images']['name'][$key];
var_dump($temp_name);
var_dump($new_name);
if(file_exists($temp_name)){
$zip->addFile($temp_name,$new_name);
move_uploaded_file($temp_name, "upload/".$new_name);
} else
echo "error file does not exist";
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
}
$res = $zip->close();
var_dump($res);
}
$zip->close() is returning false and no zip is being created.
I get no errors building up to this
$zip->numFiles shows there are files in the archive
The folder where I want to create the zip has writable permission
I am a bit lost of what else I can test for, any ideas would be great!
zip->close() method do some processing (actual compression, or just getting/writing file attributes), which require that files, added to archive, to exist.
However you are removing input files from the original location with move_uploaded_file() call.
$ref_id = mysql_insert_id();
$locatie = 'iso_photo/afwijkingen';
if($_FILES['uploaded']['type'] != 'application/octet-stream') // Geen php files
{
$folder = $locatie.basename($_FILES['uploaded'][$ref_id.'.jpg']) ;
move_uploaded_file($_FILES['uploaded']['tmp_name'], $folder);
}
Gives:
Warning: move_uploaded_file(iso_photo/afwijkingen) [function.move-uploaded-file]: failed to open stream: Is a directory
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php6LQCqY' to 'iso_photo/afwijkingen'
What might be wrong?
edited 4th line, should work now
$locatie = 'iso_photo/afwijkingen';
if($_FILES['uploaded']['type'] != 'application/octet-stream') // Geen php files
{
$folder = $locatie . "/" . basename($_FILES['uploaded'][$ref_id]) ;
move_uploaded_file($_FILES['uploaded']['tmp_name'], $folder);
}
but can't properly say, as i don't know content of $ref_id variable