$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
Related
I'm trying to extract zip files from a folder into a subfolder. The error I'm recieving is:
Warning: ZipArchive::extractTo(XXXX): failed to open stream: Permission denied in /var/www/html/update_alerts2.php on line 97
extracted
Code :
public function extractFiles($inputDir,$outputDir) {
$files_to_extract = $this->getFiles($inputDir);
$zip = new ZipArchive();
foreach ($files_to_extract as $file) {
echo $file;
$res = $zip->open($inputDir . $file);
if ($res) {
$zip->extractTo($outputDir);
$zip->deleteName($inputDir . $file);
$zip->close();
} else {
echo 'failed, code:' . $res;
}
}
}
I've tried setting permissions to 777 but I still get the error. What are the possible ways I can fix this issue (I'm using centos7 and apache) ?
I am encountering the following error message saying:
Warning: move_uploaded_file(uploads/computer-science1.jpg): failed to open stream: No such file or directory....
while trying to move a file to a directory. above code provided.
I have also enabled the uploaded file in FileZilla to be writable and executable, is there another way of solving particular problem?
Thank you.
<?php
$upload_url = "uploads/" . $_FILES["myfile"]["name"];
$filename = $_FILES["myfile"]["name"];
move_uploaded_file($_FILES["myfile"]["tmp_name"], $upload_url);
$conn = mysqli_connect("yourhost", "username", "password", "databasename");
$sql = "INSERT INTO images (image_url, image_title) VALUES ('$upload_url','$filename') ";
$imageresults = mysqli_query( $conn,$sql );
$sql = "SELECT image_url, image_title from images";
if ($imageresults = mysqli_query( $conn, $sql )) {
while ( $currentimage = mysqli_fetch_assoc($imageresults ) ) {
echo "<div><img src= '" . $currentimage['image_url'] . "'
width='200' height='200'/><br/>" .
$currentimage['image_title'] . "</div>";
}
}
} catch( Exception $e ) {
echo $e->getMessage();
}
Your PHP script must be in a directory which contains a sub-directory, uploads/, which is writeable.
It seems as if you are attempting to move the file from its temporary location to a folder (uploads/) that either doesn't exist or that the script is unable to write to.
When you've got this message :
Warning: move_uploaded_file(uploads/computer-science1.jpg): failed to
open stream: No such file or directory....
It means that the location of the file or the location of the destination directory is not good. Maybe you can check your link path of "uploads/computer-science1.jpg"
You can use a test to check it :
if(move_uploaded_file($yourFile, $yourlocation)) {
echo 'Good ! ';
} else {
exit('Error !');
}
I just wanna ask if its possible to make directory and store the uploaded file in it to a shared folder from another pc using mkdir and move_uploaded_file. I tried doing it locally it works fine but when i try this code
if($_REQUEST['submit']){
$app_name = $_POST['name'];
$desc = $_POST['description'];
$file_url = "192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"];
$photo_loc = "192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"];
$select = $_POST['select'];
$date = date('m/d/y h:i:s A');
mkdir("192.168.3.34/testupload/files/$app_name/");
mkdir("192.168.3.34/testupload/images/$app_name/");
/* some codes here that is working */
if($file != "" ){
if (file_exists("..192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"]) && file_exists("..192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"])) {
die("File Exists");
}
move_uploaded_file($_FILES["file"]["tmp_name"],
"192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"]);
if($photo_url != "") {
move_uploaded_file($_FILES["photo"]["tmp_name"],
"192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"]);
}
$name = escape($_REQUEST['name']);
$description = escape($_REQUEST['description']);
//$query = "INSERT into files (name, description,file_name,photo_url,date_uploaded) values ('{$name}', '{$description}','{$file}', '{$photo_url}', now() )";
//mysql_query($query) or die("Error in Query" . mysql_error());
//commit();
//redirect("manage.php");
$file_loc = "192.168.3.34/testupload/files/$app_name/" . $_FILES["file"]["name"];
$photo_loc = "192.168.3.34/testupload/images/$app_name/" . $_FILES["photo"]["name"];
}
}else{
set_error("File not Found");
//redirect('manage.php');
}
i tried to change the "/" in "\" and still getting this error
Warning: mkdir() [function.mkdir]: No such file or directory in
C:\xampp\htdocs\atts_update\upload.php on line 12
Warning: mkdir() [function.mkdir]: No such file or directory in
C:\xampp\htdocs\atts_update\upload.php on line 13
Warning:
move_uploaded_file(192.168.3.34/testupload/files/1111111111111/sss.txt)
[function.move-uploaded-file]: failed to open stream: No such file or
directory in C:\xampp\htdocs\atts_update\upload.php on line 71
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'C:\xampp\tmp\php610B.tmp' to
'192.168.3.34/testupload/files/1111111111111/sss.txt' in
C:\xampp\htdocs\atts_update\upload.php on line 71
Warning:
move_uploaded_file(192.168.3.34/testupload/images/1111111111111/Picture-in-a-picture4aaa.jpg) [function.move-uploaded-file]: failed to open stream: No such file or
directory in C:\xampp\htdocs\atts_update\upload.php on line 76
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'C:\xampp\tmp\php611C.tmp' to
'192.168.3.34/testupload/images/1111111111111/Picture-in-a-picture4aaa.jpg' in C:\xampp\htdocs\atts_update\upload.php on line 76
I have this code written in PHP, im using zend server on win 7 as localhost.
<?php
$dir = $_POST['link'];
// Create DOM from URL or file
require_once 'library/simple_html_dom.php';
$html = file_get_html($dir);
foreach($html->find('img') as $element){
$image = $element->src;
$imglink = $dir . $image;
$filename = $element->src;
$parsed_url = parse_url($filename, PHP_URL_PATH);
$basename = basename($filename).PHP_EOL;
$filenameOut = __DIR__ . "/images/" . $basename;
$pos = strpos($image, 'data:image');
if ($pos===false){
$parsing = parse_url($filename, PHP_URL_HOST);
if ($parsing != NULL){
file_put_contents($filenameOut, file_get_contents($image));
}
else{
file_put_contents($filenameOut, file_get_contents($imglink));
}
}
}
?>
And it gives me this error
file_put_contents(C:\Program Files (x86)\Zend\Apache2\htdocs/images/chrome-48.png ): failed to open stream: Invalid argument
Ive tried putting ways i've read from other questions from this site, but doesnt work.
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/') . '/';