Calling PHP unlink() after move_uploaded_file() on moved file fails Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag? The Ask Question Wizard is Live!How to unlock the file after AWS S3 Helper uploading file?How do I expire a PHP session after 30 minutes?PHP File Upload ProblemsPHP File Upload - Can't Upload / Debugmove_uploaded_file failed yet permissions seem rightPHP move_uploaded_file() failing on hostPHP upload, file doesnt change using move_uploaded_file()PHP - Issue with move_uploaded_fileHow to add Image Size validation in php 5.6Retrofit - upload video to XAMPP'move_uploaded_file(): Unable to move' Multiple Files XAMPP
Storing hydrofluoric acid before the invention of plastics
What would be the ideal power source for a cybernetic eye?
ListPlot join points by nearest neighbor rather than order
Single word antonym of "flightless"
Sci-Fi book where patients in a coma ward all live in a subconscious world linked together
Why is my conclusion inconsistent with the van't Hoff equation?
Can I cast Passwall to drop an enemy into a 20-foot pit?
How to tell that you are a giant?
Why was the term "discrete" used in discrete logarithm?
Is there a (better) way to access $wpdb results?
What is the role of the transistor and diode in a soft start circuit?
Why didn't this character "real die" when they blew their stack out in Altered Carbon?
What does this icon in iOS Stardew Valley mean?
How can I make names more distinctive without making them longer?
How would the world control an invulnerable immortal mass murderer?
51k Euros annually for a family of 4 in Berlin: Is it enough?
List *all* the tuples!
Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?
In predicate logic, does existential quantification (∃) include universal quantification (∀), i.e. can 'some' imply 'all'?
Selecting the same column from Different rows Based on Different Criteria
Bete Noir -- no dairy
Can a USB port passively 'listen only'?
Identifying polygons that intersect with another layer using QGIS?
What's the purpose of writing one's academic biography in the third person?
Calling PHP unlink() after move_uploaded_file() on moved file fails
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?
The Ask Question Wizard is Live!How to unlock the file after AWS S3 Helper uploading file?How do I expire a PHP session after 30 minutes?PHP File Upload ProblemsPHP File Upload - Can't Upload / Debugmove_uploaded_file failed yet permissions seem rightPHP move_uploaded_file() failing on hostPHP upload, file doesnt change using move_uploaded_file()PHP - Issue with move_uploaded_fileHow to add Image Size validation in php 5.6Retrofit - upload video to XAMPP'move_uploaded_file(): Unable to move' Multiple Files XAMPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am sending files uploaded to my server to Amazon S3. To do this, I:
- Use
move_uploaded_file()to send file to a temp-uploads folder. - I use the S3 SDK to upload the file as an object to S3.
- I use
unlink()to delete the file. unlink()fails with Resource temporarily unavailable
Windows Server running PHP/Apache.
I can unlink later after the script is done running. Calling the unlink() command outside of the script deletes the file from the server immediately. I was trying to figure out how to maybe release the file from move_uploaded_file(), but can't find anything after searching for a while.
I do use $thumb1 = new Imagick($filetothumbnail); and create a thumbnail. But I then call
$thumb1->clear();
$thumb1->destroy();
Maybe Imagick still has the file open? However, I have tested this with an excel file which does not make a thumbnail, and the file still fails to delete from the server.
if(isset($_FILES['file'])) $ext == 'jpeg'
The upload to S3 function is:
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => s3key,
'secret' => s3secret,
],
]);
$result = $s3Client->putObject([
'Bucket' => 'bucketname',
'Key' => $filename,
'SourceFile' => $filepath,
]);
php imagick
add a comment |
I am sending files uploaded to my server to Amazon S3. To do this, I:
- Use
move_uploaded_file()to send file to a temp-uploads folder. - I use the S3 SDK to upload the file as an object to S3.
- I use
unlink()to delete the file. unlink()fails with Resource temporarily unavailable
Windows Server running PHP/Apache.
I can unlink later after the script is done running. Calling the unlink() command outside of the script deletes the file from the server immediately. I was trying to figure out how to maybe release the file from move_uploaded_file(), but can't find anything after searching for a while.
I do use $thumb1 = new Imagick($filetothumbnail); and create a thumbnail. But I then call
$thumb1->clear();
$thumb1->destroy();
Maybe Imagick still has the file open? However, I have tested this with an excel file which does not make a thumbnail, and the file still fails to delete from the server.
if(isset($_FILES['file'])) $ext == 'jpeg'
The upload to S3 function is:
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => s3key,
'secret' => s3secret,
],
]);
$result = $s3Client->putObject([
'Bucket' => 'bucketname',
'Key' => $filename,
'SourceFile' => $filepath,
]);
php imagick
2
I suspect it's the S3 SDK that's locking the file, nothing to do with move_uploaded_file.
– Barmar
Feb 27 at 21:56
Are you trying to delete the temp file that is created?
– blupointmedia
Feb 27 at 22:00
1
Please show your full code
– markt
Feb 27 at 22:06
@markt Full code added. Is the S3 perhaps not yet finished? I thought that the upload to S3 wouldn't execute further code until it was finished. Maybe just adding a delay or wait?
– cngodles
Feb 28 at 16:17
1
I will try with the full path. $_SERVER['DOCUMENT_ROOT'].'/temp-uploads/thumbs/'
– Vidal
Feb 28 at 16:22
add a comment |
I am sending files uploaded to my server to Amazon S3. To do this, I:
- Use
move_uploaded_file()to send file to a temp-uploads folder. - I use the S3 SDK to upload the file as an object to S3.
- I use
unlink()to delete the file. unlink()fails with Resource temporarily unavailable
Windows Server running PHP/Apache.
I can unlink later after the script is done running. Calling the unlink() command outside of the script deletes the file from the server immediately. I was trying to figure out how to maybe release the file from move_uploaded_file(), but can't find anything after searching for a while.
I do use $thumb1 = new Imagick($filetothumbnail); and create a thumbnail. But I then call
$thumb1->clear();
$thumb1->destroy();
Maybe Imagick still has the file open? However, I have tested this with an excel file which does not make a thumbnail, and the file still fails to delete from the server.
if(isset($_FILES['file'])) $ext == 'jpeg'
The upload to S3 function is:
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => s3key,
'secret' => s3secret,
],
]);
$result = $s3Client->putObject([
'Bucket' => 'bucketname',
'Key' => $filename,
'SourceFile' => $filepath,
]);
php imagick
I am sending files uploaded to my server to Amazon S3. To do this, I:
- Use
move_uploaded_file()to send file to a temp-uploads folder. - I use the S3 SDK to upload the file as an object to S3.
- I use
unlink()to delete the file. unlink()fails with Resource temporarily unavailable
Windows Server running PHP/Apache.
I can unlink later after the script is done running. Calling the unlink() command outside of the script deletes the file from the server immediately. I was trying to figure out how to maybe release the file from move_uploaded_file(), but can't find anything after searching for a while.
I do use $thumb1 = new Imagick($filetothumbnail); and create a thumbnail. But I then call
$thumb1->clear();
$thumb1->destroy();
Maybe Imagick still has the file open? However, I have tested this with an excel file which does not make a thumbnail, and the file still fails to delete from the server.
if(isset($_FILES['file'])) $ext == 'jpeg'
The upload to S3 function is:
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => [
'key' => s3key,
'secret' => s3secret,
],
]);
$result = $s3Client->putObject([
'Bucket' => 'bucketname',
'Key' => $filename,
'SourceFile' => $filepath,
]);
php imagick
php imagick
edited Feb 28 at 16:16
cngodles
asked Feb 27 at 21:53
cngodlescngodles
355410
355410
2
I suspect it's the S3 SDK that's locking the file, nothing to do with move_uploaded_file.
– Barmar
Feb 27 at 21:56
Are you trying to delete the temp file that is created?
– blupointmedia
Feb 27 at 22:00
1
Please show your full code
– markt
Feb 27 at 22:06
@markt Full code added. Is the S3 perhaps not yet finished? I thought that the upload to S3 wouldn't execute further code until it was finished. Maybe just adding a delay or wait?
– cngodles
Feb 28 at 16:17
1
I will try with the full path. $_SERVER['DOCUMENT_ROOT'].'/temp-uploads/thumbs/'
– Vidal
Feb 28 at 16:22
add a comment |
2
I suspect it's the S3 SDK that's locking the file, nothing to do with move_uploaded_file.
– Barmar
Feb 27 at 21:56
Are you trying to delete the temp file that is created?
– blupointmedia
Feb 27 at 22:00
1
Please show your full code
– markt
Feb 27 at 22:06
@markt Full code added. Is the S3 perhaps not yet finished? I thought that the upload to S3 wouldn't execute further code until it was finished. Maybe just adding a delay or wait?
– cngodles
Feb 28 at 16:17
1
I will try with the full path. $_SERVER['DOCUMENT_ROOT'].'/temp-uploads/thumbs/'
– Vidal
Feb 28 at 16:22
2
2
I suspect it's the S3 SDK that's locking the file, nothing to do with move_uploaded_file.
– Barmar
Feb 27 at 21:56
I suspect it's the S3 SDK that's locking the file, nothing to do with move_uploaded_file.
– Barmar
Feb 27 at 21:56
Are you trying to delete the temp file that is created?
– blupointmedia
Feb 27 at 22:00
Are you trying to delete the temp file that is created?
– blupointmedia
Feb 27 at 22:00
1
1
Please show your full code
– markt
Feb 27 at 22:06
Please show your full code
– markt
Feb 27 at 22:06
@markt Full code added. Is the S3 perhaps not yet finished? I thought that the upload to S3 wouldn't execute further code until it was finished. Maybe just adding a delay or wait?
– cngodles
Feb 28 at 16:17
@markt Full code added. Is the S3 perhaps not yet finished? I thought that the upload to S3 wouldn't execute further code until it was finished. Maybe just adding a delay or wait?
– cngodles
Feb 28 at 16:17
1
1
I will try with the full path. $_SERVER['DOCUMENT_ROOT'].'/temp-uploads/thumbs/'
– Vidal
Feb 28 at 16:22
I will try with the full path. $_SERVER['DOCUMENT_ROOT'].'/temp-uploads/thumbs/'
– Vidal
Feb 28 at 16:22
add a comment |
2 Answers
2
active
oldest
votes
A quick look at the docs suggests that the upload is asynchronous:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_promises.html
And you should probably use a promise to create a callback in which you can unlink your file. There are plenty of code examples in the link.
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This didn't solve the locked file. Changing toBodyinstead ofSourceFileand properly opening/closing the file let meunlink()the file after upload.
– cngodles
Mar 8 at 17:19
add a comment |
This post helped solve this for me:
https://stackoverflow.com/a/41537354/1766536
Specifically, I had to use fopen/fclose and upload using Body instead of SourceFile
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54915084%2fcalling-php-unlink-after-move-uploaded-file-on-moved-file-fails%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A quick look at the docs suggests that the upload is asynchronous:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_promises.html
And you should probably use a promise to create a callback in which you can unlink your file. There are plenty of code examples in the link.
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This didn't solve the locked file. Changing toBodyinstead ofSourceFileand properly opening/closing the file let meunlink()the file after upload.
– cngodles
Mar 8 at 17:19
add a comment |
A quick look at the docs suggests that the upload is asynchronous:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_promises.html
And you should probably use a promise to create a callback in which you can unlink your file. There are plenty of code examples in the link.
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This didn't solve the locked file. Changing toBodyinstead ofSourceFileand properly opening/closing the file let meunlink()the file after upload.
– cngodles
Mar 8 at 17:19
add a comment |
A quick look at the docs suggests that the upload is asynchronous:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_promises.html
And you should probably use a promise to create a callback in which you can unlink your file. There are plenty of code examples in the link.
A quick look at the docs suggests that the upload is asynchronous:
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_promises.html
And you should probably use a promise to create a callback in which you can unlink your file. There are plenty of code examples in the link.
answered Feb 28 at 20:18
marktmarkt
841720
841720
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This didn't solve the locked file. Changing toBodyinstead ofSourceFileand properly opening/closing the file let meunlink()the file after upload.
– cngodles
Mar 8 at 17:19
add a comment |
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This didn't solve the locked file. Changing toBodyinstead ofSourceFileand properly opening/closing the file let meunlink()the file after upload.
– cngodles
Mar 8 at 17:19
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This will likely be the correct answer. I was wondering about that. I started to read about using promises within and got sidetracked. Thank you so much.
– cngodles
Feb 28 at 20:25
This didn't solve the locked file. Changing to
Body instead of SourceFile and properly opening/closing the file let me unlink() the file after upload.– cngodles
Mar 8 at 17:19
This didn't solve the locked file. Changing to
Body instead of SourceFile and properly opening/closing the file let me unlink() the file after upload.– cngodles
Mar 8 at 17:19
add a comment |
This post helped solve this for me:
https://stackoverflow.com/a/41537354/1766536
Specifically, I had to use fopen/fclose and upload using Body instead of SourceFile
add a comment |
This post helped solve this for me:
https://stackoverflow.com/a/41537354/1766536
Specifically, I had to use fopen/fclose and upload using Body instead of SourceFile
add a comment |
This post helped solve this for me:
https://stackoverflow.com/a/41537354/1766536
Specifically, I had to use fopen/fclose and upload using Body instead of SourceFile
This post helped solve this for me:
https://stackoverflow.com/a/41537354/1766536
Specifically, I had to use fopen/fclose and upload using Body instead of SourceFile
answered Mar 8 at 17:18
cngodlescngodles
355410
355410
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54915084%2fcalling-php-unlink-after-move-uploaded-file-on-moved-file-fails%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I suspect it's the S3 SDK that's locking the file, nothing to do with move_uploaded_file.
– Barmar
Feb 27 at 21:56
Are you trying to delete the temp file that is created?
– blupointmedia
Feb 27 at 22:00
1
Please show your full code
– markt
Feb 27 at 22:06
@markt Full code added. Is the S3 perhaps not yet finished? I thought that the upload to S3 wouldn't execute further code until it was finished. Maybe just adding a delay or wait?
– cngodles
Feb 28 at 16:17
1
I will try with the full path. $_SERVER['DOCUMENT_ROOT'].'/temp-uploads/thumbs/'
– Vidal
Feb 28 at 16:22