Hello fellow phpers 😉
I am new here so i'll introduce my self first.
I am bryan, i am 17 years old and i'm from the netherlands. My hobbys are designing, developing (websites) gaming, music and anything to do with computers.
Recently i made a website for someone i know and she needed a file uploader to. So ofcourse i build it.
I took the template from w3schools and heavily modified it to make it my own and to make it readable etc. And it worked. Estatic as i was i uploaded the uploader and tested it...it didn't work...
It keeps on saying move uploaded file won't work.
This is the basic structure of the script:
- Check for input
- Make some variables
- Database Connection
- Insert into database
- Move uploaded file to a folder
The last thing is what it trips over.
Now after about 2 weeks of changing and testing i contacted the hosting provider and well, they don't know either, but they are running a clouded server (wich means the directory is spread across several servers)
But strangely enough PHP and my FTP client have completely seperate idea's of the document root;
FTP: 0:/domains/<insert a domain name>l/htdocs/www/
PHP: /htdocs
Is there anyone who can tell me what is going on?
It keeps saying the folder does not exist and i am 100000000000000000% sure it does.
Here is my processing:
<?php
/***************
* Display errors
****************/
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
/*****************
* Set errror stuff
******************/
$aError = Array();
$bError = FALSE;
/***********************
* create a db connection
************************/
$host = 'xxxx';
$user = 'xxxx';
$pass = 'xxxxx';
$database = 'xxxxx';
$connection = @mysql_connect($host,$user,$pass);
if(!$connection){
$aError[] = 'Could not connect to database';
$bError = TRUE;
}
$database_connection = @mysql_select_db($database,$connection);
if(!$database_connection){
$aError[] = 'Could not select database';
$bError = TRUE;
}
/*************************
* Check if posts were made
**************************/
if(!isset($_POST['naam'])){
$aError[] = 'Er is een fout opgetreden, probeer het opnieuw (File of naam waren niet geset)';
$bError = TRUE;
}
/*****************
* Check file types
******************/
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/pjpeg"))&& ($_FILES["file"]["size"] < 2000000)){
/******************
* Check file errors
*******************/
if ($_FILES['file']['error'] > 0){
$aError[] = "File errors ".$_FILES['file']['error'];
$bError = TRUE;
}
/************
* Escape vars
*************/
if(trim($_POST['naam']) == ''){
$filename = mysql_real_escape_string($_FILES['file']['name']);
$storage = $_SERVER['DOCUMENT_ROOT']."/www/Fotos/"; // this also needs to be a root
}else{
$filename = mysql_real_escape_string($_POST['naam']);
$storage = $_SERVER['DOCUMENT_ROOT']."/www/Fotos/"; // this needs to be a root
}
$filename = trim($filename);
$filesize = mysql_real_escape_string($_FILES['file']['size']);
$filelocation = $storage;
$filelocation = mysql_real_escape_string($filelocation);
/***************
* Insert into DB
****************/
$query = "INSERT INTO fotos (f_name,f_size,f_location) VALUES ('".$filename."','".$filesize."','".$filelocation."')";
$mysql = @mysql_query($query);
/*******************
* Check if it worked
********************/
if(!$mysql){
$aError[] = 'Kon geen gegevens verwerken '.mysql_error(); // couldn't process data
$bError = TRUE;
}
/*********************
* Check if file exists
**********************/
if(file_exists("Fotos/".$filename)){
$aError[] = "Het bestand dat u probeert te uploaden bestaat al!"; // already exists
$bError = TRUE;
}else{
/**************
* Move the file
***************/
if(!move_uploaded_file($filename,"Fotos/")){
echo "Fout"; // file upload didn't succed
echo $filename;
}else{
echo "Goed"; // file upload succed
echo $filename;
}
}
}else{
$aError[] = "Incorrect File";
$bError = TRUE;
}
?>
I hope someone knows the anwser.
sincerely yours,
Bryan a.k.a. Fakey