Question

Im uploading pdfs with this code below:

$folder = '../uploads/pdfs';
$year = date('Y');
$month = date('m');
$pdf = $_FILES['pdf'];
$ext = substr($pdf['name'],-3);
$pdf_name = $pdf['name'].'-FROM-'.$date_begin.'-TO-'.$date_end.'';
$f['pdf'] = $year.'/'.$month.'/'.$pdf_name.'.'.$ext;
move_uploaded_file($pdf['tmp_name'], $folder.$year.'/'.$month.'/'.$pdf["name"]);

Im my sql table when I do the insert, Im getting this in my pdf_name field:

2014/05/F:\Xampp\tmp\phpE92C.tmp

And I want to save my pdf in sql like this:

2014/05/nameofpdf.pdf

Do you see what Im doing wrong here?

My insert sql statment:

$inseretInPdf = $pdo->prepare("INSERT INTO pdfs (pdf_name, date_begin, date_end) VALUES (:pdf_name, :date_begin, :date_end)");  
$inseretInPdf->bindValue(':pdf_name', $f['pdf']);
$inseretInPdf->bindValue(':date_begin', $f['date_begin']);
$inseretInPdf->bindValue(':date_end', $f['date_end']);
$inseretInPdf->execute();
Was it helpful?

Solution

Your passing the full path with $inseretInPdf->bindValue(':pdf_name', $f['pdf']);

which is:

$f['pdf'] = $year .'/'.$month .'/'.$f['url'].'.'.$ext; 2014 / 05 / F:\Xampp\tmp\phpE92C . tmp

So change $f['pdf'] to what you want it to display when it's added to the database.

EDIT: I updated the answer to visually show you what $f was passing. (:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top